Skip to content

Commit

Permalink
Make some minor improvements to spell checking regex
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed Sep 28, 2024
1 parent b2e760a commit 9fe83d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
11 changes: 6 additions & 5 deletions novelwriter/gui/doceditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,12 @@ def _insertCompletion(self, pos: int, length: int, text: str) -> None:
self._completer.hide()
return

@pyqtSlot()
def _openContextFromCursor(self) -> None:
"""Open the spell check context menu at the cursor."""
self._openContextMenu(self.cursorRect().center())
return

@pyqtSlot("QPoint")
def _openContextMenu(self, pos: QPoint) -> None:
"""Open the editor context menu at a given coordinate."""
Expand Down Expand Up @@ -1938,11 +1944,6 @@ def _emitRenameItem(self, block: QTextBlock) -> None:
self.requestProjectItemRenamed.emit(self._docHandle, text)
return

def _openContextFromCursor(self) -> None:
"""Open the spell check context menu at the cursor."""
self._openContextMenu(self.cursorRect().center())
return

def _docAutoReplace(self, text: str) -> None:
"""Auto-replace text elements based on main configuration."""
cursor = self.textCursor()
Expand Down
11 changes: 5 additions & 6 deletions novelwriter/gui/dochighlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,14 @@ def spellCheck(self, text: str, offset: int) -> list[tuple[int, int]]:
"""
if "[" in text:
# Strip shortcodes
for regEx in [RX_FMT_SC, RX_FMT_SV]:
for match in regEx.finditer(text, offset):
if (s := match.start(0)) >= 0 and (e := match.end(0)) >= 0:
pad = " "*(e - s)
text = f"{text[:s]}{pad}{text[e:]}"
for rX in [RX_FMT_SC, RX_FMT_SV]:
for match in rX.finditer(text, offset):
if (iS := match.start(0)) >= 0 and (iE := match.end(0)) >= 0:
text = text[:iS] + " "*(iE - iS) + text[iE:]

self._spellErrors = []
checker = SHARED.spelling
for match in RX_WORDS.finditer(text.replace("_", " ")):
for match in RX_WORDS.finditer(text.replace("_", " "), offset):
if (
(word := match.group(0))
and not (word.isnumeric() or word.isupper() or checker.checkWord(word))
Expand Down

0 comments on commit 9fe83d5

Please sign in to comment.