Add support for indexing and auto-completing story notes
This commit is contained in:
@@ -618,6 +618,10 @@ class Index:
|
|||||||
"""Return all story structure keys."""
|
"""Return all story structure keys."""
|
||||||
return self._itemIndex.allStoryKeys()
|
return self._itemIndex.allStoryKeys()
|
||||||
|
|
||||||
|
def getNoteKeys(self) -> set[str]:
|
||||||
|
"""Return all note comment keys."""
|
||||||
|
return self._itemIndex.allNoteKeys()
|
||||||
|
|
||||||
def novelStructure(
|
def novelStructure(
|
||||||
self, rootHandle: str | None = None, activeOnly: bool = True
|
self, rootHandle: str | None = None, activeOnly: bool = True
|
||||||
) -> Iterable[tuple[str, str, str, IndexHeading]]:
|
) -> Iterable[tuple[str, str, str, IndexHeading]]:
|
||||||
@@ -920,11 +924,12 @@ class IndexCache:
|
|||||||
which provides lookup capabilities and caching for shared data.
|
which provides lookup capabilities and caching for shared data.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ("story", "tags")
|
__slots__ = ("note", "story", "tags")
|
||||||
|
|
||||||
def __init__(self, tagsIndex: TagsIndex) -> None:
|
def __init__(self, tagsIndex: TagsIndex) -> None:
|
||||||
self.tags: TagsIndex = tagsIndex
|
self.tags: TagsIndex = tagsIndex
|
||||||
self.story: set[str] = set()
|
self.story: set[str] = set()
|
||||||
|
self.note: set[str] = set()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
@@ -979,6 +984,10 @@ class ItemIndex:
|
|||||||
"""Return all story structure keys."""
|
"""Return all story structure keys."""
|
||||||
return self._cache.story.copy()
|
return self._cache.story.copy()
|
||||||
|
|
||||||
|
def allNoteKeys(self) -> set[str]:
|
||||||
|
"""Return all note comment keys."""
|
||||||
|
return self._cache.note.copy()
|
||||||
|
|
||||||
def allItemTags(self, tHandle: str) -> list[str]:
|
def allItemTags(self, tHandle: str) -> list[str]:
|
||||||
"""Get all tags set for headings of an item."""
|
"""Get all tags set for headings of an item."""
|
||||||
if tHandle in self._items:
|
if tHandle in self._items:
|
||||||
|
|||||||
@@ -316,6 +316,9 @@ class IndexHeading:
|
|||||||
case "story" if key:
|
case "story" if key:
|
||||||
self._cache.story.add(key)
|
self._cache.story.add(key)
|
||||||
self._comments[f"story.{key}"] = str(text)
|
self._comments[f"story.{key}"] = str(text)
|
||||||
|
case "note" if key:
|
||||||
|
self._cache.note.add(key)
|
||||||
|
self._comments[f"note.{key}"] = str(text)
|
||||||
return
|
return
|
||||||
|
|
||||||
def setTag(self, tag: str) -> None:
|
def setTag(self, tag: str) -> None:
|
||||||
@@ -395,7 +398,7 @@ class IndexHeading:
|
|||||||
self.addReference(tag, keyword)
|
self.addReference(tag, keyword)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Heading reference contains an invalid keyword")
|
raise ValueError("Heading reference contains an invalid keyword")
|
||||||
elif key == "summary" or key.startswith("story"):
|
elif key == "summary" or key.startswith(("story", "note")):
|
||||||
comment, _, kind = str(key).partition(".")
|
comment, _, kind = str(key).partition(".")
|
||||||
self.setComment(comment, compact(kind), str(entry))
|
self.setComment(comment, compact(kind), str(entry))
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -2099,8 +2099,8 @@ class CommandCompleter(QMenu):
|
|||||||
if pos <= len(kw):
|
if pos <= len(kw):
|
||||||
offset = 0
|
offset = 0
|
||||||
length = len(kw.rstrip())
|
length = len(kw.rstrip())
|
||||||
suffix = "" if sep else ": "
|
suffix = "" if sep else ":"
|
||||||
options = list(filter(
|
options = sorted(filter(
|
||||||
lambda x: x.startswith(kw.rstrip()), nwKeyWords.VALID_KEYS
|
lambda x: x.startswith(kw.rstrip()), nwKeyWords.VALID_KEYS
|
||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
@@ -2143,6 +2143,15 @@ class CommandCompleter(QMenu):
|
|||||||
lambda x: x.startswith(key.rstrip()),
|
lambda x: x.startswith(key.rstrip()),
|
||||||
SHARED.project.index.getStoryKeys(),
|
SHARED.project.index.getStoryKeys(),
|
||||||
))
|
))
|
||||||
|
elif clean[:5] == "note.":
|
||||||
|
pre, _, key = cmd.partition(".")
|
||||||
|
offset = len(pre) + 1
|
||||||
|
length = len(key)
|
||||||
|
suffix = "" if sep else ": "
|
||||||
|
options = sorted(filter(
|
||||||
|
lambda x: x.startswith(key.rstrip()),
|
||||||
|
SHARED.project.index.getNoteKeys(),
|
||||||
|
))
|
||||||
elif pos < 12:
|
elif pos < 12:
|
||||||
offset = 0
|
offset = 0
|
||||||
length = len(cmd.rstrip())
|
length = len(cmd.rstrip())
|
||||||
|
|||||||
Reference in New Issue
Block a user