diff --git a/novelwriter/gui/dochighlight.py b/novelwriter/gui/dochighlight.py index 0554beb3..ddbdcaa3 100644 --- a/novelwriter/gui/dochighlight.py +++ b/novelwriter/gui/dochighlight.py @@ -168,7 +168,8 @@ class GuiDocHighlighter(QSyntaxHighlighter): } self._txtRules.append((rxRule, hlRule)) - if sym := CONFIG.dialogLine: + if CONFIG.dialogLine: + sym = QRegularExpression.escape(CONFIG.dialogLine) rxRule = QRegularExpression(f"^{sym}.*?$") rxRule.setPatternOptions(QRegExUnicode) hlRule = { @@ -176,7 +177,8 @@ class GuiDocHighlighter(QSyntaxHighlighter): } self._txtRules.append((rxRule, hlRule)) - if sym := CONFIG.narratorBreak: + if CONFIG.narratorBreak: + sym = QRegularExpression.escape(CONFIG.narratorBreak) rxRule = QRegularExpression(f"({sym}\\b)(.*?)(\\b{sym})") rxRule.setPatternOptions(QRegExUnicode) hlRule = { diff --git a/tests/reference/baseConfig_novelwriter.conf b/tests/reference/baseConfig_novelwriter.conf index 668c3fb9..818f4280 100644 --- a/tests/reference/baseConfig_novelwriter.conf +++ b/tests/reference/baseConfig_novelwriter.conf @@ -1,5 +1,5 @@ [Meta] -timestamp = 2024-04-13 18:57:38 +timestamp = 2024-05-13 15:59:59 [Main] theme = default @@ -59,9 +59,12 @@ showlineendings = False showmultispaces = True incnoteswcount = True showfullpath = True -highlightquotes = True -allowopensquote = False -allowopendquote = True +dialogstyle = 2 +allowopendial = True +narratorbreak = +altdialogopen = +altdialogclose = +dialogline = highlightemph = True stopwhenidle = True useridletime = 300 diff --git a/tests/test_dialogs/test_dlg_preferences.py b/tests/test_dialogs/test_dlg_preferences.py index 59e705ff..360c339f 100644 --- a/tests/test_dialogs/test_dlg_preferences.py +++ b/tests/test_dialogs/test_dlg_preferences.py @@ -266,18 +266,21 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths): assert CONFIG.autoScrollPos == 30 # Text Highlighting - prefs.allowOpenSQuote.setChecked(True) - prefs.allowOpenDQuote.setChecked(False) - prefs.highlightQuotes.setChecked(False) + prefs.dialogStyle.setCurrentData(3, 0) + prefs.allowOpenDial.setChecked(False) + prefs.narratorBreak.setText("–") + prefs.dialogLine.setText("–") + prefs.altDialogOpen.setText("<") + prefs.altDialogClose.setText(">") prefs.highlightEmph.setChecked(False) prefs.showMultiSpaces.setChecked(False) - assert prefs.allowOpenSQuote.isEnabled() is False - assert prefs.allowOpenDQuote.isEnabled() is False - - assert CONFIG.highlightQuotes is True - assert CONFIG.allowOpenSQuote is False - assert CONFIG.allowOpenDQuote is True + assert CONFIG.dialogStyle == 2 + assert CONFIG.allowOpenDial is True + assert CONFIG.narratorBreak == "" + assert CONFIG.dialogLine == "" + assert CONFIG.altDialogOpen == "" + assert CONFIG.altDialogClose == "" assert CONFIG.highlightEmph is True assert CONFIG.showMultiSpaces is True @@ -384,9 +387,12 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths): assert CONFIG.autoScrollPos == 31 # Text Highlighting - assert CONFIG.highlightQuotes is False - assert CONFIG.allowOpenSQuote is True - assert CONFIG.allowOpenDQuote is False + assert CONFIG.dialogStyle == 3 + assert CONFIG.allowOpenDial is False + assert CONFIG.narratorBreak == "–" + assert CONFIG.dialogLine == "–" + assert CONFIG.altDialogOpen == "<" + assert CONFIG.altDialogClose == ">" assert CONFIG.highlightEmph is False assert CONFIG.showMultiSpaces is False diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py index 4027a953..e128503c 100644 --- a/tests/test_gui/test_gui_guimain.py +++ b/tests/test_gui/test_gui_guimain.py @@ -231,7 +231,15 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd): # Text Editor # =========== - docEditor: GuiDocEditor = nwGUI.docEditor + # Syntax Highlighting + CONFIG.dialogStyle = 3 + CONFIG.dialogLine = "–" + CONFIG.narratorBreak = "–" + CONFIG.altDialogOpen = "<|" + CONFIG.altDialogClose = "|>" + + docEditor = nwGUI.docEditor + docEditor._qDocument.syntaxHighlighter.initHighlighter() # Type something into the document nwGUI.switchFocus(nwWidget.EDITOR)