diff --git a/novelwriter/core/tokenizer.py b/novelwriter/core/tokenizer.py index 10abd1fc..d33d5b62 100644 --- a/novelwriter/core/tokenizer.py +++ b/novelwriter/core/tokenizer.py @@ -1137,15 +1137,10 @@ class Tokenizer(ABC): # Match Dialogue if self._rxDialogue: for regEx, fmtB, fmtE in self._rxDialogue: - rxItt = regEx.globalMatch(text, 0) - rxMatch = regEx.match(text, 0) - if rxMatch.hasMatch(): + if (rxMatch := regEx.match(text, 0)).hasMatch(): temp.append((rxMatch.capturedStart(0), 0, fmtB, "")) temp.append((rxMatch.capturedEnd(0), 0, fmtE, "")) - print(text) - print(temp) - # Post-process text and format result = text formats = [] diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index 6b16f021..3de5af24 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -2030,6 +2030,9 @@ class GuiDocEditor(QPlainTextEdit): cursor.movePosition(QtMoveLeft, QtKeepAnchor, nDelete) cursor.insertText(tInsert) + # Re-highlight, since the auto-replace sometimes interferes with it + self._qDocument.syntaxHighlighter.rehighlightBlock(cursor.block()) + return @staticmethod diff --git a/novelwriter/text/patterns.py b/novelwriter/text/patterns.py index 2965b1c9..094b287c 100644 --- a/novelwriter/text/patterns.py +++ b/novelwriter/text/patterns.py @@ -96,7 +96,7 @@ class RegExPatterns: def narratorBreak(self) -> QRegularExpression: """Dialogue narrator break rule based on user settings.""" sym = QRegularExpression.escape(CONFIG.narratorBreak) - rxRule = QRegularExpression(f"{sym}\\b.*?\\b{sym}") + rxRule = QRegularExpression(f"\\B{sym}\\S.*?\\S{sym}\\B") rxRule.setPatternOptions(QRegExUnicode) return rxRule