From 0826a2f8a37039ee26ead042874a7ac0fb9bb415 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 23 May 2021 16:17:05 +0200 Subject: [PATCH] Remove trailing space highlight and add highlight of redundant spaces --- nw/assets/themes/syntax/default_dark.conf | 2 +- nw/assets/themes/syntax/default_light.conf | 2 +- nw/assets/themes/syntax/grey_dark.conf | 2 +- nw/assets/themes/syntax/grey_light.conf | 2 +- nw/assets/themes/syntax/light_owl.conf | 2 +- nw/assets/themes/syntax/night_owl.conf | 2 +- nw/assets/themes/syntax/solarized_dark.conf | 2 +- nw/assets/themes/syntax/solarized_light.conf | 2 +- nw/assets/themes/syntax/tomorrow.conf | 2 +- nw/assets/themes/syntax/tomorrow_night.conf | 2 +- .../themes/syntax/tomorrow_night_blue.conf | 2 +- .../themes/syntax/tomorrow_night_bright.conf | 2 +- .../syntax/tomorrow_night_eighties.conf | 2 +- nw/config.py | 5 +++ nw/dialogs/preferences.py | 16 ++++++++++ nw/gui/dochighlight.py | 32 +++++++++++-------- nw/gui/theme.py | 4 +-- tests/reference/baseConfig_novelwriter.conf | 1 + .../reference/guiPreferences_novelwriter.conf | 1 + tests/test_gui/test_gui_theme.py | 2 +- 20 files changed, 57 insertions(+), 30 deletions(-) diff --git a/nw/assets/themes/syntax/default_dark.conf b/nw/assets/themes/syntax/default_dark.conf index 09b292ee..f015e5d6 100644 --- a/nw/assets/themes/syntax/default_dark.conf +++ b/nw/assets/themes/syntax/default_dark.conf @@ -20,6 +20,6 @@ hidden = 150, 150, 150 keyword = 200, 46, 0 value = 184, 200, 0 spellcheckline = 200, 46, 0 -tagerror = 46, 200, 0 +errorline = 46, 200, 0 replacetag = 0, 184, 46 modifier = 200, 120, 0 diff --git a/nw/assets/themes/syntax/default_light.conf b/nw/assets/themes/syntax/default_light.conf index 908fd7cb..319fbda3 100644 --- a/nw/assets/themes/syntax/default_light.conf +++ b/nw/assets/themes/syntax/default_light.conf @@ -20,6 +20,6 @@ hidden = 100, 100, 100 keyword = 200, 50, 50 value = 50, 150, 50 spellcheckline = 200, 0, 0 -tagerror = 0, 150, 0 +errorline = 0, 150, 0 replacetag = 0, 150, 0 modifier = 150, 110, 30 diff --git a/nw/assets/themes/syntax/grey_dark.conf b/nw/assets/themes/syntax/grey_dark.conf index a6bc0420..e579e8da 100644 --- a/nw/assets/themes/syntax/grey_dark.conf +++ b/nw/assets/themes/syntax/grey_dark.conf @@ -20,6 +20,6 @@ hidden = 150, 150, 150 keyword = 225, 225, 225 value = 200, 200, 200 spellcheckline = 200, 46, 0 -tagerror = 46, 200, 0 +errorline = 46, 200, 0 replacetag = 225, 225, 225 modifier = 225, 225, 225 diff --git a/nw/assets/themes/syntax/grey_light.conf b/nw/assets/themes/syntax/grey_light.conf index a44593b4..32f9561c 100644 --- a/nw/assets/themes/syntax/grey_light.conf +++ b/nw/assets/themes/syntax/grey_light.conf @@ -20,6 +20,6 @@ hidden = 100, 100, 100 keyword = 0, 0, 0 value = 20, 20, 20 spellcheckline = 200, 0, 0 -tagerror = 0, 150, 0 +errorline = 0, 150, 0 replacetag = 0, 0, 0 modifier = 0, 0, 0 diff --git a/nw/assets/themes/syntax/light_owl.conf b/nw/assets/themes/syntax/light_owl.conf index fde36665..fdd0dc67 100644 --- a/nw/assets/themes/syntax/light_owl.conf +++ b/nw/assets/themes/syntax/light_owl.conf @@ -40,6 +40,6 @@ hidden = 152, 159, 177 keyword = 222, 61, 58 value = 150, 74, 193 spellcheckline = 222, 61, 58 -tagerror = 8, 145, 106 +errorline = 8, 145, 106 replacetag = 42, 162, 152 modifier = 224, 175, 5 diff --git a/nw/assets/themes/syntax/night_owl.conf b/nw/assets/themes/syntax/night_owl.conf index 56cebf53..59ad10da 100644 --- a/nw/assets/themes/syntax/night_owl.conf +++ b/nw/assets/themes/syntax/night_owl.conf @@ -40,6 +40,6 @@ hidden = 99, 119, 119 keyword = 247, 140, 108 value = 199, 146, 234 spellcheckline = 247, 140, 108 -tagerror = 173, 219, 103 +errorline = 173, 219, 103 replacetag = 127, 219, 202 modifier = 236, 196, 141 diff --git a/nw/assets/themes/syntax/solarized_dark.conf b/nw/assets/themes/syntax/solarized_dark.conf index 965430bb..ec8a3d8d 100644 --- a/nw/assets/themes/syntax/solarized_dark.conf +++ b/nw/assets/themes/syntax/solarized_dark.conf @@ -20,6 +20,6 @@ hidden = 147, 161, 161 keyword = 133, 153, 0 value = 203, 75, 22 spellcheckline = 203, 75, 22 -tagerror = 220, 50, 47 +errorline = 220, 50, 47 replacetag = 133, 153, 0 modifier = 181, 137, 0 diff --git a/nw/assets/themes/syntax/solarized_light.conf b/nw/assets/themes/syntax/solarized_light.conf index 2d1f6d1c..319a084c 100644 --- a/nw/assets/themes/syntax/solarized_light.conf +++ b/nw/assets/themes/syntax/solarized_light.conf @@ -20,6 +20,6 @@ hidden = 88, 110, 117 keyword = 133, 153, 0 value = 203, 75, 22 spellcheckline = 203, 75, 22 -tagerror = 220, 50, 47 +errorline = 220, 50, 47 replacetag = 133, 153, 0 modifier = 181, 137, 0 diff --git a/nw/assets/themes/syntax/tomorrow.conf b/nw/assets/themes/syntax/tomorrow.conf index 85fe84ea..6333f06e 100644 --- a/nw/assets/themes/syntax/tomorrow.conf +++ b/nw/assets/themes/syntax/tomorrow.conf @@ -40,6 +40,6 @@ hidden = 142, 144, 140 keyword = 240, 40, 41 value = 137, 89, 168 spellcheckline = 240, 40, 41 -tagerror = 113, 140, 0 +errorline = 113, 140, 0 replacetag = 62, 153, 159 modifier = 245, 135, 31 diff --git a/nw/assets/themes/syntax/tomorrow_night.conf b/nw/assets/themes/syntax/tomorrow_night.conf index be8f2d4d..2a4e8751 100644 --- a/nw/assets/themes/syntax/tomorrow_night.conf +++ b/nw/assets/themes/syntax/tomorrow_night.conf @@ -40,6 +40,6 @@ hidden = 150, 152, 150 keyword = 204, 102, 102 value = 178, 148, 187 spellcheckline = 204, 102, 102 -tagerror = 181, 189, 104 +errorline = 181, 189, 104 replacetag = 138, 190, 183 modifier = 222, 147, 95 diff --git a/nw/assets/themes/syntax/tomorrow_night_blue.conf b/nw/assets/themes/syntax/tomorrow_night_blue.conf index 3738051f..1a8459bf 100644 --- a/nw/assets/themes/syntax/tomorrow_night_blue.conf +++ b/nw/assets/themes/syntax/tomorrow_night_blue.conf @@ -40,6 +40,6 @@ hidden = 114, 133, 183 keyword = 255, 157, 164 value = 235, 187, 255 spellcheckline = 255, 157, 164 -tagerror = 209, 241, 169 +errorline = 209, 241, 169 replacetag = 153, 255, 255 modifier = 255, 197, 143 diff --git a/nw/assets/themes/syntax/tomorrow_night_bright.conf b/nw/assets/themes/syntax/tomorrow_night_bright.conf index 9ce48b6a..c5bccc99 100644 --- a/nw/assets/themes/syntax/tomorrow_night_bright.conf +++ b/nw/assets/themes/syntax/tomorrow_night_bright.conf @@ -40,6 +40,6 @@ hidden = 150, 152, 150 keyword = 213, 78, 83 value = 195, 151, 216 spellcheckline = 213, 78, 83 -tagerror = 185, 202, 74 +errorline = 185, 202, 74 replacetag = 112, 192, 177 modifier = 231, 140, 69 diff --git a/nw/assets/themes/syntax/tomorrow_night_eighties.conf b/nw/assets/themes/syntax/tomorrow_night_eighties.conf index 9d611cd3..c7314f17 100644 --- a/nw/assets/themes/syntax/tomorrow_night_eighties.conf +++ b/nw/assets/themes/syntax/tomorrow_night_eighties.conf @@ -40,6 +40,6 @@ hidden = 153, 153, 153 keyword = 242, 119, 122 value = 204, 153, 204 spellcheckline = 242, 119, 122 -tagerror = 153, 204, 153 +errorline = 153, 204, 153 replacetag = 102, 204, 204 modifier = 249, 145, 57 diff --git a/nw/config.py b/nw/config.py index 65436608..16647abd 100644 --- a/nw/config.py +++ b/nw/config.py @@ -138,6 +138,7 @@ class Config: self.doJustify = False # Justify text self.showTabsNSpaces = False # Show tabs and spaces in edior self.showLineEndings = False # Show line endings in editor + self.showMultiSpaces = True # Highlight multiple spaces in the text self.doReplace = True # Enable auto-replace as you type self.doReplaceSQuote = True # Smart single quotes @@ -602,6 +603,9 @@ class Config: self.showLineEndings = self._parseLine( cnfParse, cnfSec, "showlineendings", self.CNF_BOOL, self.showLineEndings ) + self.showMultiSpaces = self._parseLine( + cnfParse, cnfSec, "showmultispaces", self.CNF_BOOL, self.showMultiSpaces + ) self.bigDocLimit = self._parseLine( cnfParse, cnfSec, "bigdoclimit", self.CNF_INT, self.bigDocLimit ) @@ -765,6 +769,7 @@ class Config: cnfParse.set(cnfSec, "spellcheck", str(self.spellLanguage)) cnfParse.set(cnfSec, "showtabsnspaces", str(self.showTabsNSpaces)) cnfParse.set(cnfSec, "showlineendings", str(self.showLineEndings)) + cnfParse.set(cnfSec, "showmultispaces", str(self.showMultiSpaces)) cnfParse.set(cnfSec, "bigdoclimit", str(self.bigDocLimit)) cnfParse.set(cnfSec, "showfullpath", str(self.showFullPath)) cnfParse.set(cnfSec, "highlightquotes", str(self.highlightQuotes)) diff --git a/nw/dialogs/preferences.py b/nw/dialogs/preferences.py index 5ed23996..2680dc64 100644 --- a/nw/dialogs/preferences.py +++ b/nw/dialogs/preferences.py @@ -924,6 +924,19 @@ class GuiPreferencesSyntax(QWidget): self.tr("Applies to emphasis (italic) and strong (bold).") ) + # Text Errors + # =========== + + self.mainForm.addGroupLabel(self.tr("Text Errors")) + + self.showMultiSpaces = QSwitch() + self.showMultiSpaces.setChecked(self.mainConf.showMultiSpaces) + self.mainForm.addRow( + self.tr("Mark redundant spaces"), + self.showMultiSpaces, + self.tr("Trailing spaces or multiple spaces between words.") + ) + return def saveValues(self): @@ -940,6 +953,9 @@ class GuiPreferencesSyntax(QWidget): # Text Emphasis self.mainConf.highlightEmph = self.highlightEmph.isChecked() + # Text Errors + self.mainConf.showMultiSpaces = self.showMultiSpaces.isChecked() + self.mainConf.confChanged = True return diff --git a/nw/gui/dochighlight.py b/nw/gui/dochighlight.py index ea9df173..ceeacf45 100644 --- a/nw/gui/dochighlight.py +++ b/nw/gui/dochighlight.py @@ -71,7 +71,7 @@ class GuiDocHighlighter(QSyntaxHighlighter): self.colKey = QColor(0, 0, 0) self.colVal = QColor(0, 0, 0) self.colSpell = QColor(0, 0, 0) - self.colTagErr = QColor(0, 0, 0) + self.colError = QColor(0, 0, 0) self.colRepTag = QColor(0, 0, 0) self.initHighlighter() @@ -95,11 +95,11 @@ class GuiDocHighlighter(QSyntaxHighlighter): self.colKey = QColor(*self.theTheme.colKey) self.colVal = QColor(*self.theTheme.colVal) self.colSpell = QColor(*self.theTheme.colSpell) - self.colTagErr = QColor(*self.theTheme.colTagErr) + self.colError = QColor(*self.theTheme.colError) self.colRepTag = QColor(*self.theTheme.colRepTag) self.colMod = QColor(*self.theTheme.colMod) - self.colTrail = QColor(*self.theTheme.colEmph) - self.colTrail.setAlpha(64) + self.colBreak = QColor(*self.theTheme.colEmph) + self.colBreak.setAlpha(64) self.colEmph = None if self.mainConf.highlightEmph: @@ -117,8 +117,8 @@ class GuiDocHighlighter(QSyntaxHighlighter): "bold" : self._makeFormat(self.colEmph, "bold"), "italic" : self._makeFormat(self.colEmph, "italic"), "strike" : self._makeFormat(self.colHidden, "strike"), - "trailing" : self._makeFormat(self.colTrail, "background"), - "nobreak" : self._makeFormat(self.colTrail, "background"), + "mspaces" : self._makeFormat(self.colError, "errline"), + "nobreak" : self._makeFormat(self.colBreak, "background"), "dialogue1" : self._makeFormat(self.colDialN), "dialogue2" : self._makeFormat(self.colDialD), "dialogue3" : self._makeFormat(self.colDialS), @@ -131,12 +131,13 @@ class GuiDocHighlighter(QSyntaxHighlighter): self.hRules = [] - # Trailing Spaces, 2+ - self.hRules.append(( - r"[ ]{2,}$", { - 0 : self.hStyles["trailing"], - } - )) + # Multiple or Trailing Spaces + if self.mainConf.showMultiSpaces: + self.hRules.append(( + r"[ ]{2,}|[ ]*$", { + 0 : self.hStyles["mspaces"], + } + )) # Non-Breaking Spaces self.hRules.append(( @@ -174,7 +175,7 @@ class GuiDocHighlighter(QSyntaxHighlighter): } )) - # Markdown + # Markdown Syntax self.hRules.append(( nwRegEx.FMT_EI, { 1 : self.hStyles["hidden"], @@ -296,7 +297,7 @@ class GuiDocHighlighter(QSyntaxHighlighter): self.setFormat(xPos, xLen, self.hStyles["value"]) else: kwFmt = self.format(xPos) - kwFmt.setUnderlineColor(self.colTagErr) + kwFmt.setUnderlineColor(self.colError) kwFmt.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline) self.setFormat(xPos, xLen, kwFmt) @@ -391,6 +392,9 @@ class GuiDocHighlighter(QSyntaxHighlighter): theFormat.setFontItalic(True) if "strike" in fmtStyle: theFormat.setFontStrikeOut(True) + if "errline" in fmtStyle: + theFormat.setUnderlineColor(self.colError) + theFormat.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline) if "underline" in fmtStyle: theFormat.setFontUnderline(True) if "background" in fmtStyle: diff --git a/nw/gui/theme.py b/nw/gui/theme.py index cec8ee4e..32d5f0dc 100644 --- a/nw/gui/theme.py +++ b/nw/gui/theme.py @@ -106,7 +106,7 @@ class GuiTheme: self.colKey = [0, 0, 0] self.colVal = [0, 0, 0] self.colSpell = [0, 0, 0] - self.colTagErr = [0, 0, 0] + self.colError = [0, 0, 0] self.colRepTag = [0, 0, 0] self.colMod = [0, 0, 0] @@ -373,7 +373,7 @@ class GuiTheme: self.colKey = self._loadColour(confParser, cnfSec, "keyword") self.colVal = self._loadColour(confParser, cnfSec, "value") self.colSpell = self._loadColour(confParser, cnfSec, "spellcheckline") - self.colTagErr = self._loadColour(confParser, cnfSec, "tagerror") + self.colError = self._loadColour(confParser, cnfSec, "errorline") self.colRepTag = self._loadColour(confParser, cnfSec, "replacetag") self.colMod = self._loadColour(confParser, cnfSec, "modifier") diff --git a/tests/reference/baseConfig_novelwriter.conf b/tests/reference/baseConfig_novelwriter.conf index cfbf4e78..1f8ba2d7 100644 --- a/tests/reference/baseConfig_novelwriter.conf +++ b/tests/reference/baseConfig_novelwriter.conf @@ -55,6 +55,7 @@ spelltool = internal spellcheck = en showtabsnspaces = False showlineendings = False +showmultispaces = True bigdoclimit = 800 showfullpath = True highlightquotes = True diff --git a/tests/reference/guiPreferences_novelwriter.conf b/tests/reference/guiPreferences_novelwriter.conf index 80e77d34..1be38593 100644 --- a/tests/reference/guiPreferences_novelwriter.conf +++ b/tests/reference/guiPreferences_novelwriter.conf @@ -55,6 +55,7 @@ spelltool = internal spellcheck = en showtabsnspaces = True showlineendings = True +showmultispaces = True bigdoclimit = 500 showfullpath = False highlightquotes = False diff --git a/tests/test_gui/test_gui_theme.py b/tests/test_gui/test_gui_theme.py index 0e6b1e34..cb9c993b 100644 --- a/tests/test_gui/test_gui_theme.py +++ b/tests/test_gui/test_gui_theme.py @@ -109,7 +109,7 @@ def testGuiTheme_Main(qtbot, monkeypatch, nwMinimal, tmpDir): assert nwGUI.theTheme.colKey == [242, 119, 122] assert nwGUI.theTheme.colVal == [204, 153, 204] assert nwGUI.theTheme.colSpell == [242, 119, 122] - assert nwGUI.theTheme.colTagErr == [153, 204, 153] + assert nwGUI.theTheme.colError == [153, 204, 153] assert nwGUI.theTheme.colRepTag == [102, 204, 204] assert nwGUI.theTheme.colMod == [249, 145, 57]