Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(autocomplete): say so when no note matches
Elian Doranc823fae88741
diff --git a/apps/client/src/widgets/react/NoteAutocomplete.css b/apps/client/src/widgets/react/NoteAutocomplete.cssindex 7b5ee9cb86..39b08928dd 100644--- a/apps/client/src/widgets/react/NoteAutocomplete.css+++ b/apps/client/src/widgets/react/NoteAutocomplete.css@@ -104,6 +104,12 @@ span.aa-dropdown-menu .aa-suggestion {color: var(--suggestion-active-text-color);background-color: var(--suggestion-active-background-color);}++ /* A row saying something about the list, not one to pick. */+ &.disabled {+ cursor: default;+ color: var(--muted-text-color);+ }}span.aa-dropdown-menu .note-suggestion-separator {diff --git a/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx b/apps/client/src/widgets/react/NoteAutocomplete.spec.tsxindex db569b30db..b10a3deaf9 100644--- a/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx+++ b/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx@@ -672,6 +672,35 @@ describe("NoteAutocomplete's suggestion list", () => {expect(allRows().at(-1)?.classList.contains("tn-menu-active")).toBe(true);});+ it("says no note matched ahead of the rows acting on the query, in both kinds of list", async () => {+ getNoteSuggestions.mockResolvedValue([ searchRow, createRow ]);+ const input = await mount();+ await type(input, "New");++ const menu = document.querySelector(".note-autocomplete-menu .tn-menu-scroll");+ const first = menu?.firstElementChild;+ expect(first?.classList.contains("disabled")).toBe(true);+ expect(first?.getAttribute("role")).toBeNull();+ expect(first?.querySelector(".bx-info-circle")).not.toBeNull();+ expect(first?.nextElementSibling?.className).toBe("dropdown-divider");+ // Not a row the keys reach: the list still opens on creating the note.+ expect(allRows().find((row) => row.classList.contains("tn-menu-active"))?.querySelector(".bx-plus")).not.toBeNull();++ const host = document.createElement("div");+ document.body.append(host);+ const contained = await mount({ container: { current: host } });+ await type(contained, "New");+ const firstContained = host.querySelector(".aa-suggestions")?.firstElementChild;+ expect(firstContained?.classList.contains("disabled")).toBe(true);+ expect(firstContained?.nextElementSibling?.className).toBe("note-suggestion-separator");+ host.remove();++ // A list with notes needs no such row.+ getNoteSuggestions.mockResolvedValue([ ...notes, createRow ]);+ await type(input, "al");+ expect(document.querySelector(".note-autocomplete-menu .tn-menu-scroll > .disabled")).toBeNull();+ });+it("opens on creating the note when no note matches, past the search rows ahead of it", async () => {getNoteSuggestions.mockResolvedValue([ searchRow, createRow ]);const input = await mount();@@ -713,9 +742,11 @@ describe("NoteAutocomplete's suggestion list", () => {const input = await mount({ onChange });await type(input, "al");- expect(rows()[0].querySelectorAll(".note-suggestion-shortcut > kbd")).toHaveLength(2);- // No notes above the search rows to set them apart from.- expect(document.querySelector(".note-autocomplete-menu .dropdown-divider")).toBeNull();+ expect(allRows().find((row) => row.querySelector(".bx-file-find"))?.querySelectorAll(".note-suggestion-shortcut > kbd")).toHaveLength(2);+ // One line, under the row saying no note matched.+ const dividers = document.querySelectorAll(".note-autocomplete-menu .dropdown-divider");+ expect(dividers).toHaveLength(1);+ expect(dividers[0].previousElementSibling?.classList.contains("disabled")).toBe(true);// Past the full-text search row ahead of it.await press(input, "ArrowDown");await press(input, "Enter");diff --git a/apps/client/src/widgets/react/NoteAutocomplete.tsx b/apps/client/src/widgets/react/NoteAutocomplete.tsxindex db25cd18fa..c8464dd776 100644--- a/apps/client/src/widgets/react/NoteAutocomplete.tsx+++ b/apps/client/src/widgets/react/NoteAutocomplete.tsx@@ -364,6 +364,12 @@ function NoteSuggestionList({ autocomplete, searchingFor }: {<NoteSuggestion suggestion={{ noteTitle: searchingFor, highlightedNotePathTitle: t("quick-search.searching") }} /></div>)}+ {searchingFor === undefined && listsNoNote(autocomplete.items) && <>+ <div className="aa-suggestion disabled">+ <NoteSuggestion suggestion={noNotesRow()} />+ </div>+ <div className="note-suggestion-separator" role="separator" />+ </>}{searchingFor === undefined && autocomplete.items.map((suggestion, index) => [startsGroup(autocomplete.items, index) && <div key={`separator-${index}`} className="note-suggestion-separator" role="separator" />,<div@@ -405,6 +411,12 @@ function NoteSuggestionMenu({ autocomplete, searchingFor }: {<NoteSuggestionMenuItem suggestion={{ noteTitle: searchingFor, highlightedNotePathTitle: t("quick-search.searching") }} /></li>)}+ {searchingFor === undefined && listsNoNote(autocomplete.items) && <>+ <li className="dropdown-item disabled">+ <NoteSuggestionMenuItem suggestion={noNotesRow()} />+ </li>+ <FormDropdownDivider />+ </>}{searchingFor === undefined && autocomplete.items.map((suggestion, index) => [startsGroup(autocomplete.items, index) && <FormDropdownDivider key={`divider-${index}`} />,<li@@ -517,6 +529,19 @@ function createWhenNoNote(items: Suggestion[]) {: items.findIndex((suggestion) => suggestion.action === "create-note");}+/**+ * Whether a query listed rows but no note, so that the search and creation rows do not read as notes+ * on their own: the lists then open with a disabled row saying so.+ */+function listsNoNote(items: Suggestion[]) {+ return items.length > 0 && !items.some((suggestion) => rowGroup(suggestion) === "note");+}++/** The disabled row opening a list that holds no note, built when rendered so that it is translated. */+function noNotesRow(): Suggestion {+ return { icon: "bx bx-info-circle", highlightedNotePathTitle: t("quick-search.no-results") };+}+/** Whether a line goes above the row at `index`: the first of a group, after the rows of another. */function startsGroup(items: Suggestion[], index: number) {return index > 0 && rowGroup(items[index]) !== rowGroup(items[index - 1]);diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.htmlindex f303f15b5b..e0d4ee77e0 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.html@@ -49,9 +49,10 @@</ul></li><li>The options are listed after the notes: first those that search further,- then those that create a note. <kbd>Enter</kbd> opens the note that matches- best, or creates the note when none matches. Otherwise, press <kbd>↑</kbd> from- the first note to reach the options to create a note.</li>+ then those that create a note. When no note matches, the list says so above+ them. <kbd>Enter</kbd> opens the note that matches best, or creates the note+ when none matches. Otherwise, press <kbd>↑</kbd> from the first note to reach+ the options to create a note.</li></ul><h2>Recent notes</h2><p>Jump to note also has the ability to show the list of recently vieweddiff --git a/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.md b/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.mdindex b44dd0e84b..f6988d8963 100644--- a/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.md+++ b/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.md@@ -22,7 +22,7 @@ In addition to searching for notes, it is also possible to search for commands.* When the title search does not find a note, the two options at the end of the list search further:* _Include note contents in the results_ searches the content of the notes as well as their titles, and lists what it finds in place of the current results, without leaving the dialog. Press <kbd>Shift</kbd>+<kbd>Enter</kbd> to run it without selecting it.* _Show all results in full search_ opens the query in the full <a class="reference-link" href="Search.md">Search</a>, in a new tab, where its options can refine it. Press <kbd>Ctrl</kbd>+<kbd>Enter</kbd> to run it without selecting it.-* The options are listed after the notes: first those that search further, then those that create a note. <kbd>Enter</kbd> opens the note that matches best, or creates the note when none matches. Otherwise, press <kbd>↑</kbd> from the first note to reach the options to create a note.+* The options are listed after the notes: first those that search further, then those that create a note. When no note matches, the list says so above them. <kbd>Enter</kbd> opens the note that matches best, or creates the note when none matches. Otherwise, press <kbd>↑</kbd> from the first note to reach the options to create a note.## Recent notes