From 683e81c57bfff9b685c34e0babec8e13f94834a2 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 16 Jun 2024 21:13:50 +0200 Subject: [PATCH] Connect rehighlight tags in editor to index signal on tags change (#1916) --- novelwriter/gui/doceditor.py | 12 +++++++----- novelwriter/guimain.py | 2 +- tests/test_gui/test_gui_doceditor.py | 1 - 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index 6581d601..b54df758 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -436,11 +436,6 @@ class GuiDocEditor(QPlainTextEdit): return True - def updateTagHighLighting(self) -> None: - """Rerun the syntax highlighter on all meta data lines.""" - self._qDocument.syntaxHighlighter.rehighlightByType(BLOCK_META) - return - def replaceText(self, text: str) -> None: """Replace the text of the current document with the provided text. This also clears undo history. @@ -1034,6 +1029,13 @@ class GuiDocEditor(QPlainTextEdit): self.beginSearch() return + @pyqtSlot(list, list) + def updateChangedTags(self, updated: list[str], deleted: list[str]) -> None: + """Tags have changed, so just in case we rehighlight them.""" + if updated or deleted: + self._qDocument.syntaxHighlighter.rehighlightByType(BLOCK_META) + return + ## # Private Slots ## diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index ed4b1650..f23d2b4b 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -215,6 +215,7 @@ class GuiMain(QMainWindow): SHARED.spellLanguageChanged.connect(self.mainStatus.setLanguage) SHARED.focusModeChanged.connect(self._focusModeChanged) SHARED.indexChangedTags.connect(self.docViewerPanel.updateChangedTags) + SHARED.indexChangedTags.connect(self.docEditor.updateChangedTags) SHARED.indexScannedText.connect(self.docViewerPanel.projectItemChanged) SHARED.indexScannedText.connect(self.projView.updateItemValues) SHARED.indexScannedText.connect(self.itemDetails.updateViewBox) @@ -745,7 +746,6 @@ class GuiMain(QMainWindow): self.mainStatus.setStatusMessage( self.tr("Indexing completed in {0} ms").format(f"{(tEnd - tStart)*1000.0:.1f}") ) - self.docEditor.updateTagHighLighting() self._updateStatusWordCount() QApplication.restoreOverrideCursor() diff --git a/tests/test_gui/test_gui_doceditor.py b/tests/test_gui/test_gui_doceditor.py index 6c8ed7a6..2ed80e96 100644 --- a/tests/test_gui/test_gui_doceditor.py +++ b/tests/test_gui/test_gui_doceditor.py @@ -1597,7 +1597,6 @@ def testGuiEditor_Tags(qtbot, nwGUI, projPath, ipsumText, mockRnd): docEditor.replaceText(text) nwGUI.saveDocument() assert nwGUI.projView.projTree.revealNewTreeItem(cHandle) - docEditor.updateTagHighLighting() # Follow Tag # ==========