From bc43e924fef62414b5eeb496864206c6100c9e83 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 12 Nov 2019 21:24:13 +0100 Subject: [PATCH] Strip non-word characters when adding to user dictionary --- nw/gui/elements/doceditor.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/nw/gui/elements/doceditor.py b/nw/gui/elements/doceditor.py index a3c0a440..c961f301 100644 --- a/nw/gui/elements/doceditor.py +++ b/nw/gui/elements/doceditor.py @@ -53,6 +53,7 @@ class GuiDocEditor(QTextEdit): self.wordCount = 0 self.paraCount = 0 self.lastEdit = 0 + self.nonWord = "\"'" # Typography self.typDQOpen = self.mainConf.fmtDoubleQuotes[0] @@ -137,6 +138,11 @@ class GuiDocEditor(QTextEdit): created, and when the user changes the main editor preferences. """ + # Some Constants + self.nonWord = "\"'" + self.nonWord += "".join(self.mainConf.fmtDoubleQuotes) + self.nonWord += "".join(self.mainConf.fmtSingleQuotes) + # Reload spell check and dictionaries self._setupSpellChecking() self.setDictionaries() @@ -500,7 +506,7 @@ class GuiDocEditor(QTextEdit): theCursor = self.cursorForPosition(thePos) theCursor.select(QTextCursor.WordUnderCursor) - theWord = theCursor.selectedText() + theWord = theCursor.selectedText().strip().strip(self.nonWord) if theWord == "": return if self.theDict.checkWord(theWord): @@ -541,7 +547,7 @@ class GuiDocEditor(QTextEdit): return def _addWord(self, theCursor): - theWord = theCursor.selectedText().strip() + theWord = theCursor.selectedText().strip().strip(self.nonWord) logger.debug("Added '%s' to project dictionary" % theWord) self.theDict.addWord(theWord) self.hLight.setDict(self.theDict)