Fix missing tag display in outline (#2429)

This commit is contained in:
Veronica Berglyd Olsen
2025-06-24 16:23:15 +02:00
committed by GitHub
7 changed files with 32 additions and 17 deletions
+8 -6
View File
@@ -708,17 +708,19 @@ class Index:
return 0, 0, 0 return 0, 0, 0
def getReferences(self, tHandle: str, sTitle: str | None = None) -> dict[str, list[str]]: def getReferences(self, tHandle: str, sTitle: str | None = None) -> dict[str, list[str]]:
"""Extract all references made in a file, and optionally title """Extract all tags and references made in a file, and
section. optionally title section.
""" """
tRefs = {x: [] for x in nwKeyWords.VALID_KEYS} refs = {x: [] for x in nwKeyWords.VALID_KEYS}
for rTitle, hItem in self._itemIndex.iterItemHeaders(tHandle): for rTitle, hItem in self._itemIndex.iterItemHeaders(tHandle):
if sTitle is None or sTitle == rTitle: if sTitle is None or sTitle == rTitle:
for aTag, refTypes in hItem.references.items(): for aTag, refTypes in hItem.references.items():
for refType in refTypes: for refType in refTypes:
if refType in tRefs: if refType in refs:
tRefs[refType].append(self._tagsIndex.tagName(aTag)) refs[refType].append(self._tagsIndex.tagName(aTag))
return tRefs if tag := hItem.tag:
refs[nwKeyWords.TAG_KEY] = [self._tagsIndex.tagName(tag)]
return refs
def getReferenceForHeader(self, tHandle: str, nHead: int, keyClass: str) -> list[str]: def getReferenceForHeader(self, tHandle: str, nHead: int, keyClass: str) -> list[str]:
"""Get the display names for a tags class for insertion into a """Get the display names for a tags class for insertion into a
+9 -3
View File
@@ -342,20 +342,26 @@ class IndexHeading:
## ##
def getReferences(self) -> dict[str, list[str]]: def getReferences(self) -> dict[str, list[str]]:
"""Extract all references for this heading.""" """Extract all tags and references for this heading."""
refs = {x: [] for x in nwKeyWords.VALID_KEYS} refs = {x: [] for x in nwKeyWords.VALID_KEYS}
for tag, types in self._refs.items(): for tag, types in self._refs.items():
for keyword in types: for keyword in types:
if keyword in refs and (name := self._cache.tags.tagName(tag)): if keyword in refs and (name := self._cache.tags.tagName(tag)):
refs[keyword].append(name) refs[keyword].append(name)
if name := self._cache.tags.tagName(self._tag):
refs[nwKeyWords.TAG_KEY] = [name]
return refs return refs
def getReferencesByKeyword(self, keyword: str) -> list[str]: def getReferencesByKeyword(self, keyword: str) -> list[str]:
"""Extract all references for this heading.""" """Extract all references for this heading."""
refs = [] refs = []
for tag, types in self._refs.items(): if keyword == nwKeyWords.TAG_KEY:
if keyword in types and (name := self._cache.tags.tagName(tag)): if name := self._cache.tags.tagName(self._tag):
refs.append(name) refs.append(name)
else:
for tag, types in self._refs.items():
if keyword in types and (name := self._cache.tags.tagName(tag)):
refs.append(name)
return refs return refs
## ##
+1
View File
@@ -593,6 +593,7 @@ class GuiNovelTree(NTreeView):
lines = [] lines = []
if head := SHARED.project.index.getItemHeading(tHandle, sTitle): if head := SHARED.project.index.getItemHeading(tHandle, sTitle):
tags = head.getReferences() tags = head.getReferences()
appendTags(tags, nwKeyWords.TAG_KEY, lines)
appendTags(tags, nwKeyWords.POV_KEY, lines) appendTags(tags, nwKeyWords.POV_KEY, lines)
appendTags(tags, nwKeyWords.FOCUS_KEY, lines) appendTags(tags, nwKeyWords.FOCUS_KEY, lines)
appendTags(tags, nwKeyWords.CHAR_KEY, lines) appendTags(tags, nwKeyWords.CHAR_KEY, lines)
+3 -2
View File
@@ -1,10 +1,11 @@
%%~name: Making a Scene %%~name: Making a Scene
%%~path: 6a2d6d5f4f401/636b6aa9b697b %%~path: 6a2d6d5f4f401/636b6aa9b697b
%%~kind: NOVEL/DOCUMENT %%~kind: NOVEL/DOCUMENT
%%~hash: 1f3d98a6a27b4f9a7f2239fcd78f9e2263cd3b97 %%~hash: b39201b02e3db63493d61d09e5fec5765a937255
%%~date: Unknown/2025-05-18 22:36:59 %%~date: Unknown/2025-06-24 09:09:56
### Making a Scene ### Making a Scene
@tag: Scene
@pov: Jane @pov: Jane
@char: John, Jane @char: John, Jane
@location: Earth @location: Earth
+3 -3
View File
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="2.7.1" hexVersion="0x020701f0" fileVersion="1.5" fileRevision="5" timeStamp="2025-06-09 22:54:50"> <novelWriterXML appVersion="2.7.1" hexVersion="0x020701f0" fileVersion="1.5" fileRevision="5" timeStamp="2025-06-24 16:14:48">
<project id="e2be99af-f9bf-4403-857a-c3d1ac25abea" saveCount="2194" autoCount="286" editTime="96892"> <project id="e2be99af-f9bf-4403-857a-c3d1ac25abea" saveCount="2208" autoCount="287" editTime="97150">
<name>Sample Project</name> <name>Sample Project</name>
<author>Jane Smith</author> <author>Jane Smith</author>
</project> </project>
@@ -58,7 +58,7 @@
<name status="sf24ce6" import="ia857f0" active="yes">Chapter One</name> <name status="sf24ce6" import="ia857f0" active="yes">Chapter One</name>
</item> </item>
<item handle="636b6aa9b697b" parent="6a2d6d5f4f401" root="7031beac91f75" order="0" type="FILE" class="NOVEL" layout="DOCUMENT"> <item handle="636b6aa9b697b" parent="6a2d6d5f4f401" root="7031beac91f75" order="0" type="FILE" class="NOVEL" layout="DOCUMENT">
<meta expanded="no" heading="H3" charCount="2999" wordCount="530" paraCount="16" cursorPos="718" /> <meta expanded="no" heading="H3" charCount="2999" wordCount="530" paraCount="16" cursorPos="93" />
<name status="s90e6c9" import="ia857f0" active="yes">Making a Scene</name> <name status="s90e6c9" import="ia857f0" active="yes">Making a Scene</name>
</item> </item>
<item handle="bc0cbd2a407f3" parent="6a2d6d5f4f401" root="7031beac91f75" order="1" type="FILE" class="NOVEL" layout="DOCUMENT"> <item handle="bc0cbd2a407f3" parent="6a2d6d5f4f401" root="7031beac91f75" order="1" type="FILE" class="NOVEL" layout="DOCUMENT">
+4 -1
View File
@@ -695,6 +695,7 @@ def testCoreIndex_ExtractData(nwGUI, fncPath, mockRnd):
)) ))
assert index.scanText(nHandle, ( assert index.scanText(nHandle, (
"# Hello World!\n" "# Hello World!\n"
"@tag: Scene\n"
"@pov: Jane\n" "@pov: Jane\n"
"@char: Jane, John\n\n" "@char: Jane, John\n\n"
"% this is a comment\n\n" "% this is a comment\n\n"
@@ -749,11 +750,13 @@ def testCoreIndex_ExtractData(nwGUI, fncPath, mockRnd):
# Look up an invalid handle # Look up an invalid handle
refs = index.getReferences("Not a handle") refs = index.getReferences("Not a handle")
assert refs["@tag"] == []
assert refs["@pov"] == [] assert refs["@pov"] == []
assert refs["@char"] == [] assert refs["@char"] == []
# The novel file should now refer to Jane as @pov and @char # The novel file should now refer to Jane as @pov and @char
refs = index.getReferences(nHandle) refs = index.getReferences(nHandle)
assert refs["@tag"] == ["Scene"]
assert refs["@pov"] == ["Jane"] assert refs["@pov"] == ["Jane"]
assert refs["@char"] == ["Jane", "John"] assert refs["@char"] == ["Jane", "John"]
@@ -791,7 +794,7 @@ def testCoreIndex_ExtractData(nwGUI, fncPath, mockRnd):
# getKeyWordTags # getKeyWordTags
# ============== # ==============
assert index.getKeyWordTags("@mention") == ["Jane", "John"] assert index.getKeyWordTags("@mention") == ["Jane", "John", "Scene"]
assert index.getKeyWordTags("@char") == ["Jane", "John"] assert index.getKeyWordTags("@char") == ["Jane", "John"]
assert index.getKeyWordTags("@plot") == [] assert index.getKeyWordTags("@plot") == []
assert index.getKeyWordTags("@tag") == [] assert index.getKeyWordTags("@tag") == []
+4 -2
View File
@@ -267,6 +267,7 @@ def testCoreIndexData_IndexHeadingReferences():
head = IndexHeading(cache, "T0001") head = IndexHeading(cache, "T0001")
# Add some references # Add some references
head.setTag("Scene")
head.addReference("Jane", "@pov") head.addReference("Jane", "@pov")
head.addReference("Jane", "@char") head.addReference("Jane", "@char")
head.addReference("John", "@char") head.addReference("John", "@char")
@@ -290,6 +291,7 @@ def testCoreIndexData_IndexHeadingReferences():
} }
# Set names # Set names
cache.tags.add("Scene", "Scene", "0000000000000", "T00001", "NOVEL")
cache.tags.add("Jane", "Jane", "0000000000000", "T00001", "CHARACTER") cache.tags.add("Jane", "Jane", "0000000000000", "T00001", "CHARACTER")
cache.tags.add("John", "John", "0000000000000", "T00001", "CHARACTER") cache.tags.add("John", "John", "0000000000000", "T00001", "CHARACTER")
cache.tags.add("Main", "Main", "0000000000000", "T00001", "PLOT") cache.tags.add("Main", "Main", "0000000000000", "T00001", "PLOT")
@@ -301,7 +303,7 @@ def testCoreIndexData_IndexHeadingReferences():
"@plot": ["Main"], "@plot": ["Main"],
"@object": ["Gun"], "@object": ["Gun"],
"@story": [], "@story": [],
"@tag": [], "@tag": ["Scene"],
"@focus": [], "@focus": [],
"@custom": [], "@custom": [],
"@time": [], "@time": [],
@@ -316,7 +318,7 @@ def testCoreIndexData_IndexHeadingReferences():
assert head.getReferencesByKeyword("@plot") == ["Main"] assert head.getReferencesByKeyword("@plot") == ["Main"]
assert head.getReferencesByKeyword("@object") == ["Gun"] assert head.getReferencesByKeyword("@object") == ["Gun"]
assert head.getReferencesByKeyword("@story") == [] assert head.getReferencesByKeyword("@story") == []
assert head.getReferencesByKeyword("@tag") == [] assert head.getReferencesByKeyword("@tag") == ["Scene"]
assert head.getReferencesByKeyword("@focus") == [] assert head.getReferencesByKeyword("@focus") == []
assert head.getReferencesByKeyword("@custom") == [] assert head.getReferencesByKeyword("@custom") == []
assert head.getReferencesByKeyword("@time") == [] assert head.getReferencesByKeyword("@time") == []