diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index dc9b93af..bf343578 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -1043,7 +1043,7 @@ class GuiDocEditor(QPlainTextEdit): if suggest: ctxMenu.addSeparator() ctxMenu.addAction(self.tr("Spelling Suggestion(s)")) - for option in suggest: + for option in suggest[:15]: aFix = ctxMenu.addAction(f"{nwUnicode.U_ENDASH} {option}") aFix.triggered.connect( lambda _, option=option: self._correctWord(sCursor, option) @@ -1052,9 +1052,8 @@ class GuiDocEditor(QPlainTextEdit): ctxMenu.addAction("%s %s" % (nwUnicode.U_ENDASH, self.tr("No Suggestions"))) ctxMenu.addSeparator() - aAdd = QAction(self.tr("Add Word to Dictionary"), ctxMenu) + aAdd = ctxMenu.addAction(self.tr("Add Word to Dictionary")) aAdd.triggered.connect(lambda: self._addWord(word, block)) - ctxMenu.addAction(aAdd) # Execute the context menu ctxMenu.exec_(self.viewport().mapToGlobal(pos)) diff --git a/novelwriter/gui/editordocument.py b/novelwriter/gui/editordocument.py index 14d7f4fd..793d82bc 100644 --- a/novelwriter/gui/editordocument.py +++ b/novelwriter/gui/editordocument.py @@ -101,17 +101,16 @@ class GuiTextDocument(QTextDocument): cursor = QTextCursor(self) cursor.setPosition(pos) block = cursor.block() - if block.isValid(): - data = block.userData() - if isinstance(data, TextBlockData): - text = block.text() - check = pos - block.position() - if check >= 0: - for cPos, cLen in data.spellErrors: - cEnd = cPos + cLen - if cPos <= check <= cEnd: - word = text[cPos:cEnd] - return word, cPos, cLen, SHARED.spelling.suggestWords(word) + data = block.userData() + if block.isValid() and isinstance(data, TextBlockData): + text = block.text() + check = pos - block.position() + if check >= 0: + for cPos, cLen in data.spellErrors: + cEnd = cPos + cLen + if cPos <= check <= cEnd: + word = text[cPos:cEnd] + return word, cPos, cLen, SHARED.spelling.suggestWords(word) return "", -1, -1, [] # END Class GuiTextDocument