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
style(autocomplete): one line above the search rows in a contained list
Elian Doranefeeab1e2499
diff --git a/apps/client/src/widgets/dialogs/jump_to_note.css b/apps/client/src/widgets/dialogs/jump_to_note.cssindex 2ae73e11f3..fdd58f90a6 100644--- a/apps/client/src/widgets/dialogs/jump_to_note.css+++ b/apps/client/src/widgets/dialogs/jump_to_note.css@@ -54,16 +54,6 @@}-.jump-to-note-results .aa-suggestion .search-notes-action {- border-top: 1px solid var(--main-border-color);- margin-top: 8px;- padding-top: 8px;-}--.jump-to-note-results .aa-suggestion:has(.search-notes-action)::after {- display: none;-}-.jump-to-note-dialog .command-icon {color: var(--muted-text-color);font-size: 1.125rem;diff --git a/apps/client/src/widgets/react/NoteAutocomplete.css b/apps/client/src/widgets/react/NoteAutocomplete.cssindex 49f392aec4..53cc227256 100644--- a/apps/client/src/widgets/react/NoteAutocomplete.css+++ b/apps/client/src/widgets/react/NoteAutocomplete.css@@ -107,6 +107,11 @@ span.aa-dropdown-menu .aa-suggestion {}}+span.aa-dropdown-menu .note-suggestion-separator {+ margin-block: 8px;+ border-top: 1px solid var(--main-border-color);+}+/* The shortcut of the row that runs a search, at the end of its title line. */.search-notes-action .text > kbd {float: inline-end;diff --git a/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx b/apps/client/src/widgets/react/NoteAutocomplete.spec.tsxindex ca9a7f77ce..26019b80b2 100644--- a/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx+++ b/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx@@ -664,6 +664,21 @@ describe("NoteAutocomplete's suggestion list", () => {expect(dividers[0].nextElementSibling).toBe(fullTextRow());});+ it("sets them apart with one line in a host's container too", async () => {+ getNoteSuggestions.mockResolvedValue([ ...notes, searchRow ]);+ const host = document.createElement("div");+ document.body.append(host);+ const input = await mount({ container: { current: host } });+ await type(input, "al");++ const separators = [ ...host.querySelectorAll(".note-suggestion-separator") ];+ const suggestions = [ ...host.querySelectorAll(".aa-suggestion") ];+ expect(separators).toHaveLength(1);+ expect(separators[0].previousElementSibling).toBe(suggestions[1]);+ expect(separators[0].nextElementSibling?.querySelector("kbd")?.textContent).toBe("Shift+Enter");+ host.remove();+ });+it("runs a search from its row, with its shortcut shown, reporting it for the host to close on", async () => {const onChange = vi.fn();getNoteSuggestions.mockResolvedValue([ searchRow ]);diff --git a/apps/client/src/widgets/react/NoteAutocomplete.tsx b/apps/client/src/widgets/react/NoteAutocomplete.tsxindex c0cbcb6522..edc341b7c2 100644--- a/apps/client/src/widgets/react/NoteAutocomplete.tsx+++ b/apps/client/src/widgets/react/NoteAutocomplete.tsx@@ -361,17 +361,19 @@ function NoteSuggestionList({ autocomplete, searchingFor }: {</div>)}{searchingFor === undefined && autocomplete.items.map((suggestion, index) => (- <div- key={`${suggestion.action ?? ""}:${suggestion.notePath ?? suggestion.commandId ?? index}`}- id={autocomplete.itemId(index)}- className={clsx("aa-suggestion", index === autocomplete.activeIndex && "aa-cursor")}- role="option"- aria-selected={index === autocomplete.activeIndex}- onMouseMove={(e) => autocomplete.hover(index, e)}- onClick={() => autocomplete.pick(suggestion)}- >- <NoteSuggestion suggestion={suggestion} />- </div>+ <Fragment key={`${suggestion.action ?? ""}:${suggestion.notePath ?? suggestion.commandId ?? index}`}>+ {startsSearchRows(autocomplete.items, index) && <div className="note-suggestion-separator" role="separator" />}+ <div+ id={autocomplete.itemId(index)}+ className={clsx("aa-suggestion", index === autocomplete.activeIndex && "aa-cursor")}+ role="option"+ aria-selected={index === autocomplete.activeIndex}+ onMouseMove={(e) => autocomplete.hover(index, e)}+ onClick={() => autocomplete.pick(suggestion)}+ >+ <NoteSuggestion suggestion={suggestion} />+ </div>+ </Fragment>))}</span></div>@@ -402,7 +404,7 @@ function NoteSuggestionMenu({ autocomplete, searchingFor }: {)}{searchingFor === undefined && autocomplete.items.map((suggestion, index) => (<Fragment key={`${suggestion.action ?? ""}:${suggestion.notePath ?? suggestion.commandId ?? index}`}>- {index > 0 && isSearchRow(suggestion) && !isSearchRow(autocomplete.items[index - 1]) && <FormDropdownDivider />}+ {startsSearchRows(autocomplete.items, index) && <FormDropdownDivider />}<liid={autocomplete.itemId(index)}className={clsx("dropdown-item", index === autocomplete.activeIndex && "tn-menu-active")}@@ -486,7 +488,11 @@ function NoteSuggestion({ suggestion }: { suggestion: Suggestion }) {);}-/** The rows that run a search for the query, which the menu sets apart from the notes above them. */+/** Whether a line goes above the row at `index`: the first of the rows searching for the query, after a note. */+function startsSearchRows(items: Suggestion[], index: number) {+ return index > 0 && isSearchRow(items[index]) && !isSearchRow(items[index - 1]);+}+function isSearchRow(suggestion: Suggestion) {return suggestion.action === "full-text-search" || suggestion.action === "search-notes";}