From 56dac84932008be0143a00c912a70c102cdf6230 Mon Sep 17 00:00:00 2001 From: mousse Date: Wed, 20 Sep 2023 16:24:55 +0200 Subject: [PATCH] issue 1224: contextmenu on unknown word in context of pyspellchecker and symspellpy --- manuskript/functions/spellchecker.py | 2 +- manuskript/ui/views/textEditView.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/manuskript/functions/spellchecker.py b/manuskript/functions/spellchecker.py index b4ae0d2..6a2ac54 100644 --- a/manuskript/functions/spellchecker.py +++ b/manuskript/functions/spellchecker.py @@ -363,7 +363,7 @@ class PySpellcheckerDictionary(BasicDictionary): def getSuggestions(self, word): candidates = self._dict.candidates(word) - if word in candidates: + if candidates and word in candidates: candidates.remove(word) return candidates diff --git a/manuskript/ui/views/textEditView.py b/manuskript/ui/views/textEditView.py index fe17c84..fbc8461 100644 --- a/manuskript/ui/views/textEditView.py +++ b/manuskript/ui/views/textEditView.py @@ -620,10 +620,11 @@ class textEditView(QTextEdit): selectedWord = cursor.selectedText() - for word in match.replacements: - action = self.SpellAction(word, spell_menu) - action.correct.connect(self.correctWord) - spell_menu.addAction(action) + if match.replacements: + for word in match.replacements: + action = self.SpellAction(word, spell_menu) + action.correct.connect(self.correctWord) + spell_menu.addAction(action) # Adds: add to dictionary addAction = QAction(self.tr("&Add to dictionary"), popup_menu) @@ -635,7 +636,7 @@ class textEditView(QTextEdit): # Only add the spelling suggests to the menu if there are # suggestions. - if len(match.replacements) > 0: + if match.replacements and len(match.replacements) > 0: # Adds: suggestions popup_menu.insertMenu(popup_menu.actions()[0], spell_menu) else: