Strip non-word characters when adding to user dictionary

This commit is contained in:
Veronica K. B. Olsen
2019-11-12 21:24:13 +01:00
parent 3089c560e5
commit bc43e924fe
+8 -2
View File
@@ -53,6 +53,7 @@ class GuiDocEditor(QTextEdit):
self.wordCount = 0 self.wordCount = 0
self.paraCount = 0 self.paraCount = 0
self.lastEdit = 0 self.lastEdit = 0
self.nonWord = "\"'"
# Typography # Typography
self.typDQOpen = self.mainConf.fmtDoubleQuotes[0] self.typDQOpen = self.mainConf.fmtDoubleQuotes[0]
@@ -137,6 +138,11 @@ class GuiDocEditor(QTextEdit):
created, and when the user changes the main editor preferences. 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 # Reload spell check and dictionaries
self._setupSpellChecking() self._setupSpellChecking()
self.setDictionaries() self.setDictionaries()
@@ -500,7 +506,7 @@ class GuiDocEditor(QTextEdit):
theCursor = self.cursorForPosition(thePos) theCursor = self.cursorForPosition(thePos)
theCursor.select(QTextCursor.WordUnderCursor) theCursor.select(QTextCursor.WordUnderCursor)
theWord = theCursor.selectedText() theWord = theCursor.selectedText().strip().strip(self.nonWord)
if theWord == "": if theWord == "":
return return
if self.theDict.checkWord(theWord): if self.theDict.checkWord(theWord):
@@ -541,7 +547,7 @@ class GuiDocEditor(QTextEdit):
return return
def _addWord(self, theCursor): def _addWord(self, theCursor):
theWord = theCursor.selectedText().strip() theWord = theCursor.selectedText().strip().strip(self.nonWord)
logger.debug("Added '%s' to project dictionary" % theWord) logger.debug("Added '%s' to project dictionary" % theWord)
self.theDict.addWord(theWord) self.theDict.addWord(theWord)
self.hLight.setDict(self.theDict) self.hLight.setDict(self.theDict)