From b9d149a56a5430be122db4ee912d9c746bd7b5b9 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 13 Apr 2023 19:22:21 +0200 Subject: [PATCH] Improve how underscores are treated by spell checker (#1415) --- novelwriter/gui/dochighlight.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/novelwriter/gui/dochighlight.py b/novelwriter/gui/dochighlight.py index d344c8f6..3b527a64 100644 --- a/novelwriter/gui/dochighlight.py +++ b/novelwriter/gui/dochighlight.py @@ -224,13 +224,11 @@ class GuiDocHighlighter(QSyntaxHighlighter): hReg.setPatternOptions(QRegularExpression.UseUnicodePropertiesOption) self.rxRules.append((hReg, regRules)) - # Build a QRegExp for spell checker + # Build a QRegExp for the spell checker # Include additional characters that the highlighter should # consider to be word separators - wordSep = r"\-_\+/" - wordSep += nwUnicode.U_ENDASH - wordSep += nwUnicode.U_EMDASH - self.spellRx = QRegularExpression(r"\b[^\s"+wordSep+r"]+\b") + uCode = nwUnicode.U_ENDASH + nwUnicode.U_EMDASH + self.spellRx = QRegularExpression(r"\b[^\s\-\+\/" + uCode + r"]+\b") self.spellRx.setPatternOptions(QRegularExpression.UseUnicodePropertiesOption) return True @@ -389,7 +387,7 @@ class GuiDocHighlighter(QSyntaxHighlighter): if not self.spellCheck: return - rxSpell = self.spellRx.globalMatch(theText, 0) + rxSpell = self.spellRx.globalMatch(theText.replace("_", " "), 0) while rxSpell.hasNext(): rxMatch = rxSpell.next() if not self.spEnchant.checkWord(rxMatch.captured(0)):