Allow words to be ignored by the spell checker (session only)

This commit is contained in:
Veronica Berglyd Olsen
2024-09-28 11:21:04 +02:00
parent 5ed03e29f3
commit a6494b4226
4 changed files with 48 additions and 43 deletions
+25 -25
View File
@@ -1164,8 +1164,10 @@ class GuiDocEditor(QPlainTextEdit):
ctxMenu.addAction(f"{nwUnicode.U_ENDASH} {trNone}")
ctxMenu.addSeparator()
action = ctxMenu.addAction(self.tr("Ignore Word"))
action.triggered.connect(lambda: self._addWord(word, block, False))
action = ctxMenu.addAction(self.tr("Add Word to Dictionary"))
action.triggered.connect(lambda: self._addWord(word, block))
action.triggered.connect(lambda: self._addWord(word, block, True))
# Execute the context menu
ctxMenu.exec(self.viewport().mapToGlobal(pos))
@@ -1173,30 +1175,6 @@ class GuiDocEditor(QPlainTextEdit):
return
@pyqtSlot("QTextCursor", str)
def _correctWord(self, cursor: QTextCursor, word: str) -> None:
"""Slot for the spell check context menu triggering the
replacement of a word with the word from the dictionary.
"""
pos = cursor.selectionStart()
cursor.beginEditBlock()
cursor.removeSelectedText()
cursor.insertText(word)
cursor.endEditBlock()
cursor.setPosition(pos)
self.setTextCursor(cursor)
return
@pyqtSlot(str, "QTextBlock")
def _addWord(self, word: str, block: QTextBlock) -> None:
"""Slot for the spell check context menu triggered when the user
wants to add a word to the project dictionary.
"""
logger.debug("Added '%s' to project dictionary", word)
SHARED.spelling.addWord(word)
self._qDocument.syntaxHighlighter.rehighlightBlock(block)
return
@pyqtSlot()
def _runDocumentTasks(self) -> None:
"""Run timer document tasks."""
@@ -1875,6 +1853,28 @@ class GuiDocEditor(QPlainTextEdit):
# Internal Functions
##
def _correctWord(self, cursor: QTextCursor, word: str) -> None:
"""Slot for the spell check context menu triggering the
replacement of a word with the word from the dictionary.
"""
pos = cursor.selectionStart()
cursor.beginEditBlock()
cursor.removeSelectedText()
cursor.insertText(word)
cursor.endEditBlock()
cursor.setPosition(pos)
self.setTextCursor(cursor)
return
def _addWord(self, word: str, block: QTextBlock, save: bool) -> None:
"""Slot for the spell check context menu triggered when the user
wants to add a word to the project dictionary.
"""
logger.debug("Added '%s' to project dictionary, %s", word, "saved" if save else "unsaved")
SHARED.spelling.addWord(word, save=save)
self._qDocument.syntaxHighlighter.rehighlightBlock(block)
return
def _processTag(self, cursor: QTextCursor | None = None,
follow: bool = True, create: bool = False) -> nwTrinary:
"""Activated by Ctrl+Enter. Checks that we're in a block