Skip to content

Commit

Permalink
Connect rehighlight tags in editor to index signal on tags change (#1916
Browse files Browse the repository at this point in the history
)
  • Loading branch information
vkbo committed Jun 16, 2024
1 parent f548927 commit 683e81c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
12 changes: 7 additions & 5 deletions novelwriter/gui/doceditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,6 @@ def loadText(self, tHandle: str, tLine: int | None = None) -> bool:

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.
Expand Down Expand Up @@ -1034,6 +1029,13 @@ def toggleSearch(self) -> None:
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
##
Expand Down
2 changes: 1 addition & 1 deletion novelwriter/guimain.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def __init__(self) -> None:
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)
Expand Down Expand Up @@ -745,7 +746,6 @@ def rebuildIndex(self, beQuiet: bool = False) -> None:
self.mainStatus.setStatusMessage(
self.tr("Indexing completed in {0} ms").format(f"{(tEnd - tStart)*1000.0:.1f}")
)
self.docEditor.updateTagHighLighting()
self._updateStatusWordCount()
QApplication.restoreOverrideCursor()

Expand Down
1 change: 0 additions & 1 deletion tests/test_gui/test_gui_doceditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ==========
Expand Down

0 comments on commit 683e81c

Please sign in to comment.