From 2ab782817926f1856fe5276fac91e43835c9afb1 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 16 Nov 2019 12:31:49 +0100 Subject: [PATCH] Added more characters as valid word separators to the highlighter regex --- nw/gui/tools/dochighlight.py | 10 ++++++++-- sample/sampleNovel/data_6/36b6aa9b697b_main.nwd | 2 ++ sample/sampleNovel/nwProject.nwx | 16 ++++++++-------- tests/profilestats.py | 2 +- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/nw/gui/tools/dochighlight.py b/nw/gui/tools/dochighlight.py index 270a5d15..fd093933 100644 --- a/nw/gui/tools/dochighlight.py +++ b/nw/gui/tools/dochighlight.py @@ -18,6 +18,8 @@ from PyQt5.QtGui import ( QColor, QTextCharFormat, QFont, QSyntaxHighlighter, QBrush ) +from nw.constants import nwUnicode + logger = logging.getLogger(__name__) class GuiDocHighlighter(QSyntaxHighlighter): @@ -150,7 +152,7 @@ class GuiDocHighlighter(QSyntaxHighlighter): # Non-breaking Space self.hRules.append(( - "[\u00a0]+", { + "[%s]+" % nwUnicode.U_NBSP, { 0 : self.hStyles["nobreak"], } )) @@ -209,7 +211,11 @@ class GuiDocHighlighter(QSyntaxHighlighter): self.rxRules.append((hReg, regRules)) # Build a QRegExp for spell checker - self.spellRx = QRegularExpression(r"\b[^\s]+\b") + # Include additional characters that the highlighter should + # consider to be word separators + wordSep = "_+" + wordSep += nwUnicode.U_EMDASH + self.spellRx = QRegularExpression("\\b[^\\s%s]+\\b" % wordSep) self.spellRx.setPatternOptions(QRegularExpression.UseUnicodePropertiesOption) return True diff --git a/sample/sampleNovel/data_6/36b6aa9b697b_main.nwd b/sample/sampleNovel/data_6/36b6aa9b697b_main.nwd index 70e5eafa..e1578fec 100644 --- a/sample/sampleNovel/data_6/36b6aa9b697b_main.nwd +++ b/sample/sampleNovel/data_6/36b6aa9b697b_main.nwd @@ -12,6 +12,8 @@ In addition, the editor supports automatic formatting of “quotes”, both doub If you have the need for it, you can also add text that can be automatically replaced by other text when you generate a preview or export the project. Now, let’s auto-replace this A with , and this C with . While is just . Press Ctrl+R to see what this looks like in the view pane. +The editor also supports non breaking spaces, and the spell checker accepts long dashes—like this—as valid word separators. + #### Some Section Here If you need to split a scene file up into further pieces, you can do so with the level four heading, like above. This is referred to as a section. diff --git a/sample/sampleNovel/nwProject.nwx b/sample/sampleNovel/nwProject.nwx index 63b80110..fe093bba 100644 --- a/sample/sampleNovel/nwProject.nwx +++ b/sample/sampleNovel/nwProject.nwx @@ -1,5 +1,5 @@ - + Sample Project Sample Project @@ -9,9 +9,9 @@ True - 96b68994dfa3d + 636b6aa9b697b b3e74dbc1f584 - 855 + 875 B E @@ -79,10 +79,10 @@ 1st Draft False SCENE - 1076 - 196 - 6 - 59 + 1199 + 216 + 7 + 949 Another Scene @@ -118,7 +118,7 @@ 1692 313 6 - 216 + 530 Chapter Two diff --git a/tests/profilestats.py b/tests/profilestats.py index f55c7b01..cbb18aeb 100755 --- a/tests/profilestats.py +++ b/tests/profilestats.py @@ -13,4 +13,4 @@ print("") profMainWindows = pstats.Stats(path.join(profDir,"testMainWindows.prof")) profMainWindows.sort_stats("cumtime") -profMainWindows.print_stats("nw",50) +profMainWindows.print_stats("nw/")