Don't highlight tags in inactive files

This commit is contained in:
Veronica Berglyd Olsen
2024-02-03 17:00:27 +01:00
parent 0a1c5b20ed
commit e78545fcdb
3 changed files with 15 additions and 11 deletions
+3 -2
View File
@@ -485,8 +485,9 @@ class NWIndex:
# For a tag, only the first value is accepted, the rest are ignored # For a tag, only the first value is accepted, the rest are ignored
if tBits[0] == nwKeyWords.TAG_KEY and nBits > 1: if tBits[0] == nwKeyWords.TAG_KEY and nBits > 1:
if tBits[1] in self._tagsIndex: check, _ = self.parseValue(tBits[1])
isGood[1] = self._tagsIndex.tagHandle(tBits[1]) == tHandle if check in self._tagsIndex:
isGood[1] = self._tagsIndex.tagHandle(check) == tHandle
else: else:
isGood[1] = True isGood[1] = True
return isGood return isGood
+8 -9
View File
@@ -60,8 +60,8 @@ class GuiDocHighlighter(QSyntaxHighlighter):
logger.debug("Create: GuiDocHighlighter") logger.debug("Create: GuiDocHighlighter")
self._tItem = None
self._tHandle = None self._tHandle = None
self._isInactive = False
self._spellCheck = False self._spellCheck = False
self._spellErr = QTextCharFormat() self._spellErr = QTextCharFormat()
@@ -238,11 +238,10 @@ class GuiDocHighlighter(QSyntaxHighlighter):
def setHandle(self, tHandle: str) -> None: def setHandle(self, tHandle: str) -> None:
"""Set the handle of the currently highlighted document.""" """Set the handle of the currently highlighted document."""
self._tHandle = tHandle self._tHandle = tHandle
self._tItem = SHARED.project.tree[tHandle] self._isInactive = (
logger.debug( item.isInactiveClass() if (item := SHARED.project.tree[tHandle]) else False
"Syntax highlighter %s for item '%s'",
"enabled" if self._tItem else "disabled", tHandle
) )
logger.debug("Syntax highlighter enabled for item '%s'", tHandle)
return return
## ##
@@ -286,16 +285,16 @@ class GuiDocHighlighter(QSyntaxHighlighter):
for n, bit in enumerate(bits): for n, bit in enumerate(bits):
xPos = pos[n] xPos = pos[n]
xLen = len(bit) xLen = len(bit)
if not isGood[n]: if n == 0 and isGood[n]:
self.setFormat(xPos, xLen, self._hStyles["codeinval"])
elif n == 0:
self.setFormat(xPos, xLen, self._hStyles["keyword"]) self.setFormat(xPos, xLen, self._hStyles["keyword"])
else: elif isGood[n] and not self._isInactive:
one, two = index.parseValue(bit) one, two = index.parseValue(bit)
self.setFormat(xPos, len(one), self._hStyles["value"]) self.setFormat(xPos, len(one), self._hStyles["value"])
if two: if two:
yPos = xPos + len(bit) - len(two) yPos = xPos + len(bit) - len(two)
self.setFormat(yPos, len(two), self._hStyles["optional"]) 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, # We never want to run the spell checker on keyword/values,
# so we force a return here # so we force a return here
+4
View File
@@ -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")
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() project.closeProject()
# END Test testCoreIndex_CheckThese # END Test testCoreIndex_CheckThese