From e10a386b6a06447ccacf5823d430f5bed5b00cec Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 12 Nov 2019 20:20:45 +0100 Subject: [PATCH 1/3] Some fixed to the spell checking part of the highlighter --- nw/gui/tools/dochighlight.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/nw/gui/tools/dochighlight.py b/nw/gui/tools/dochighlight.py index e8ac2b04..b151ac94 100644 --- a/nw/gui/tools/dochighlight.py +++ b/nw/gui/tools/dochighlight.py @@ -202,7 +202,11 @@ class GuiDocHighlighter(QSyntaxHighlighter): )) # Build a QRegExp for each pattern and for the spell checker - self.rules = [(QRegularExpression(a),b) for (a,b) in self.hRules] + self.rxRules = [] + for regEx, regRules in self.hRules: + hReg = QRegularExpression(regEx) + hReg.setPatternOptions(QRegularExpression.UseUnicodePropertiesOption) + self.rxRules.append((hReg, regRules)) self.spellRx = QRegularExpression(r"\b[^\s]+\b") self.spellRx.setPatternOptions(QRegularExpression.UseUnicodePropertiesOption) @@ -253,9 +257,12 @@ class GuiDocHighlighter(QSyntaxHighlighter): kwFmt.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline) self.setFormat(xPos, xLen, kwFmt) + # We're done, no need to continue + return + else: - # Other text just uses regex - for rX, xFmt in self.rules: + # For other text, just use our regex rules + for rX, xFmt in self.rxRules: rxItt = rX.globalMatch(theText, 0) while rxItt.hasNext(): rxMatch = rxItt.next() @@ -264,10 +271,10 @@ class GuiDocHighlighter(QSyntaxHighlighter): xLen = rxMatch.capturedLength(xM) self.setFormat(xPos, xLen, xFmt[xM]) - if self.theDict is None or not self.spellCheck or theText.startswith("@"): + if self.theDict is None or not self.spellCheck: return - rxSpell = self.spellRx.globalMatch(theText.replace("_"," "), 0) + rxSpell = self.spellRx.globalMatch(theText, 0) while rxSpell.hasNext(): rxMatch = rxSpell.next() if not self.theDict.checkWord(rxMatch.captured(0)): From 3089c560e573cd2282acd1a9fd313aa9e6fd2881 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 12 Nov 2019 21:05:48 +0100 Subject: [PATCH 2/3] Ensure the window is normal size before we might maximise it --- nw/guimain.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nw/guimain.py b/nw/guimain.py index 5d6557c5..5fa5df69 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -173,6 +173,7 @@ class GuiMain(QMainWindow): self.asDocTimer.start() self.statusBar.clearStatus() + self.showNormal() if self.mainConf.isFullScreen: self.toggleFullScreenMode() 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 3/3] 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)