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 self._itemIndex.allStoryKeys()
|
||||
|
||||
def getNoteKeys(self) -> set[str]:
|
||||
"""Return all note comment keys."""
|
||||
return self._itemIndex.allNoteKeys()
|
||||
|
||||
def novelStructure(
|
||||
self, rootHandle: str | None = None, activeOnly: bool = True
|
||||
) -> Iterable[tuple[str, str, str, IndexHeading]]:
|
||||
@@ -920,11 +924,12 @@ class IndexCache:
|
||||
which provides lookup capabilities and caching for shared data.
|
||||
"""
|
||||
|
||||
__slots__ = ("story", "tags")
|
||||
__slots__ = ("note", "story", "tags")
|
||||
|
||||
def __init__(self, tagsIndex: TagsIndex) -> None:
|
||||
self.tags: TagsIndex = tagsIndex
|
||||
self.story: set[str] = set()
|
||||
self.note: set[str] = set()
|
||||
return
|
||||
|
||||
|
||||
@@ -979,6 +984,10 @@ class ItemIndex:
|
||||
"""Return all story structure keys."""
|
||||
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]:
|
||||
"""Get all tags set for headings of an item."""
|
||||
if tHandle in self._items:
|
||||
|
||||
@@ -316,6 +316,9 @@ class IndexHeading:
|
||||
case "story" if key:
|
||||
self._cache.story.add(key)
|
||||
self._comments[f"story.{key}"] = str(text)
|
||||
case "note" if key:
|
||||
self._cache.note.add(key)
|
||||
self._comments[f"note.{key}"] = str(text)
|
||||
return
|
||||
|
||||
def setTag(self, tag: str) -> None:
|
||||
@@ -395,7 +398,7 @@ class IndexHeading:
|
||||
self.addReference(tag, keyword)
|
||||
else:
|
||||
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(".")
|
||||
self.setComment(comment, compact(kind), str(entry))
|
||||
else:
|
||||
|
||||
@@ -2099,8 +2099,8 @@ class CommandCompleter(QMenu):
|
||||
if pos <= len(kw):
|
||||
offset = 0
|
||||
length = len(kw.rstrip())
|
||||
suffix = "" if sep else ": "
|
||||
options = list(filter(
|
||||
suffix = "" if sep else ":"
|
||||
options = sorted(filter(
|
||||
lambda x: x.startswith(kw.rstrip()), nwKeyWords.VALID_KEYS
|
||||
))
|
||||
else:
|
||||
@@ -2143,6 +2143,15 @@ class CommandCompleter(QMenu):
|
||||
lambda x: x.startswith(key.rstrip()),
|
||||
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:
|
||||
offset = 0
|
||||
length = len(cmd.rstrip())
|
||||
|
||||
Reference in New Issue
Block a user