From e78545fcdbbf5b1d8af10555f94a41a64085f26e Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 3 Feb 2024 17:00:27 +0100 Subject: [PATCH] Don't highlight tags in inactive files --- novelwriter/core/index.py | 5 +++-- novelwriter/gui/dochighlight.py | 17 ++++++++--------- tests/test_core/test_core_index.py | 4 ++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/novelwriter/core/index.py b/novelwriter/core/index.py index 67d790b1..a5a781a9 100644 --- a/novelwriter/core/index.py +++ b/novelwriter/core/index.py @@ -485,8 +485,9 @@ class NWIndex: # For a tag, only the first value is accepted, the rest are ignored if tBits[0] == nwKeyWords.TAG_KEY and nBits > 1: - if tBits[1] in self._tagsIndex: - isGood[1] = self._tagsIndex.tagHandle(tBits[1]) == tHandle + check, _ = self.parseValue(tBits[1]) + if check in self._tagsIndex: + isGood[1] = self._tagsIndex.tagHandle(check) == tHandle else: isGood[1] = True return isGood diff --git a/novelwriter/gui/dochighlight.py b/novelwriter/gui/dochighlight.py index f292e2f9..91cf4efd 100644 --- a/novelwriter/gui/dochighlight.py +++ b/novelwriter/gui/dochighlight.py @@ -60,8 +60,8 @@ class GuiDocHighlighter(QSyntaxHighlighter): logger.debug("Create: GuiDocHighlighter") - self._tItem = None self._tHandle = None + self._isInactive = False self._spellCheck = False self._spellErr = QTextCharFormat() @@ -238,11 +238,10 @@ class GuiDocHighlighter(QSyntaxHighlighter): def setHandle(self, tHandle: str) -> None: """Set the handle of the currently highlighted document.""" self._tHandle = tHandle - self._tItem = SHARED.project.tree[tHandle] - logger.debug( - "Syntax highlighter %s for item '%s'", - "enabled" if self._tItem else "disabled", tHandle + self._isInactive = ( + item.isInactiveClass() if (item := SHARED.project.tree[tHandle]) else False ) + logger.debug("Syntax highlighter enabled for item '%s'", tHandle) return ## @@ -286,16 +285,16 @@ class GuiDocHighlighter(QSyntaxHighlighter): for n, bit in enumerate(bits): xPos = pos[n] xLen = len(bit) - if not isGood[n]: - self.setFormat(xPos, xLen, self._hStyles["codeinval"]) - elif n == 0: + if n == 0 and isGood[n]: self.setFormat(xPos, xLen, self._hStyles["keyword"]) - else: + elif isGood[n] and not self._isInactive: one, two = index.parseValue(bit) self.setFormat(xPos, len(one), self._hStyles["value"]) if two: yPos = xPos + len(bit) - len(two) self.setFormat(yPos, len(two), self._hStyles["optional"]) + elif not self._isInactive: + self.setFormat(xPos, xLen, self._hStyles["codeinval"]) # We never want to run the spell checker on keyword/values, # so we force a return here diff --git a/tests/test_core/test_core_index.py b/tests/test_core/test_core_index.py index 53ac33bd..f225d0f2 100644 --- a/tests/test_core/test_core_index.py +++ b/tests/test_core/test_core_index.py @@ -294,6 +294,10 @@ def testCoreIndex_CheckThese(mockGUI, fncPath, mockRnd): assert index.parseValue("Jane | Jane Smith") == ("Jane", "Jane Smith") assert index.parseValue("Jane | Jane Smith") == ("Jane", "Jane Smith") + # Duplicates with Display Name + assert index.checkThese(["@tag", "Jane | Jane Doe"], cHandle) == [True, True] + assert index.checkThese(["@tag", "Jane | Jane Smith"], nHandle) == [True, False] + project.closeProject() # END Test testCoreIndex_CheckThese