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(jump-to-note): offer the searches in a footer under the results
Elian Doran2cf09ef5058c
diff --git a/apps/client/src/stylesheets/theme-next/dialogs.css b/apps/client/src/stylesheets/theme-next/dialogs.cssindex 6919594cd6..40e1fe447a 100644--- a/apps/client/src/stylesheets/theme-next/dialogs.css+++ b/apps/client/src/stylesheets/theme-next/dialogs.css@@ -168,6 +168,20 @@ div.tn-tool-dialog {scroll-padding-top: var(--jump-to-note-fade);}+/* Above the footer, the results fade out as they do under the search field. */+.jump-to-note-dialog .jump-to-note-results .note-suggestion-list:has(+ .note-suggestion-footer) {+ --scroll-fade-bottom: var(--jump-to-note-fade);+ padding-bottom: var(--jump-to-note-fade);+ scroll-padding-bottom: var(--jump-to-note-fade);+}++/* Spans the dialog's padding on both sides; its content lines up with the rows'. */+.jump-to-note-dialog .jump-to-note-results .note-suggestion-footer {+ margin-inline: calc(0px - var(--jump-to-note-padding));+ padding: 4px calc(var(--jump-to-note-padding) + 16px) 12px;+ border-top: 0;+}+/* Search box wrapper */.jump-to-note-dialog .input-group {margin-inline-end: 16px;diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex f81648b364..c51f3da652 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -3087,7 +3087,8 @@"create-child-note": "Create child note \"{{term}}\"","insert-external-link": "Insert external link to \"{{term}}\"","clear-text-field": "Clear text field",- "include-note-contents": "Include note contents in the results for \"{{term}}\""+ "include-note-contents": "Include note contents in the results for \"{{term}}\"",+ "include-contents": "Include note contents"},"note_tooltip": {"note-has-been-deleted": "Note has been deleted.",diff --git a/apps/client/src/widgets/react/NoteAutocomplete.css b/apps/client/src/widgets/react/NoteAutocomplete.cssindex 92da406742..260e65ba9a 100644--- a/apps/client/src/widgets/react/NoteAutocomplete.css+++ b/apps/client/src/widgets/react/NoteAutocomplete.css@@ -110,6 +110,26 @@}}+/* Under a host's list, outside its scroller, so it stays in view as the list scrolls. */+.note-suggestion-footer {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 16px;+ padding: 6px 16px;+ border-top: 1px solid var(--main-border-color);++ .switch-widget {+ gap: 8px;+ }++ /* Beside the switch's label, not pushed to the end of a row. */+ .note-suggestion-shortcut {+ margin-inline-start: 0;+ padding-inline-start: 0;+ }+}+/** The keys of a search row, at the end of its title line. One line tall, as the title is, so the row* keeps the height of the others.@@ -126,7 +146,7 @@* Each key drawn as the Next theme draws a button's (`button.btn kbd` in forms.css), plainly in the* themes without its variables. The `!important`s outrank the Next theme's `.dropdown-item kbd`.*/-.dropdown-item .note-suggestion-shortcut > kbd {+:is(.dropdown-item, .note-suggestion-footer) .note-suggestion-shortcut > kbd {padding: 0.1875rem 0.375rem;border: 0;box-shadow: none;diff --git a/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx b/apps/client/src/widgets/react/NoteAutocomplete.spec.tsxindex 798a2dc015..f4609691e4 100644--- a/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx+++ b/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx@@ -441,7 +441,7 @@ describe("NoteAutocomplete's suggestion list", () => {await type(input, "a");const menu = host.querySelector<HTMLElement>(":scope > menu.note-suggestion-list");- expect(menu?.querySelectorAll(":scope > .dropdown-item")).toHaveLength(3);+ expect(menu?.querySelectorAll(":scope > .dropdown-item")).toHaveLength(2);// In the host's flow, with no position of its own.expect(menu?.hasAttribute("style")).toBe(false);expect(document.querySelector(".dropdown-menu.note-autocomplete-menu")).toBeNull();@@ -455,7 +455,7 @@ describe("NoteAutocomplete's suggestion list", () => {input.focus();input.blur();});- expect(host.querySelectorAll(".dropdown-item")).toHaveLength(3);+ expect(host.querySelectorAll(".dropdown-item")).toHaveLength(2);// Both are left to the host, as a dialog closes on Escape.const reachedHost: string[] = [];@@ -464,7 +464,7 @@ describe("NoteAutocomplete's suggestion list", () => {await press(input, "Escape");await press(input, "Tab");document.body.removeEventListener("keydown", listen);- expect(host.querySelectorAll(".dropdown-item")).toHaveLength(3);+ expect(host.querySelectorAll(".dropdown-item")).toHaveLength(2);expect(reachedHost).toEqual([ "Escape", "Tab" ]);await press(input, "Enter");@@ -769,19 +769,44 @@ 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 ]);+ it("offers the searches beside a host's list rather than in it", async () => {+ const onChange = vi.fn();const host = document.createElement("div");document.body.append(host);- const input = await mount({ container: { current: host } });+ const input = await mount({ onChange, container: { current: host }, opts: { allowJumpToSearchNotes: true } });await type(input, "al");- const separators = [ ...host.querySelectorAll(".note-suggestion-list > .dropdown-divider") ];- const suggestions = [ ...host.querySelectorAll(".note-suggestion-list > .dropdown-item") ];- expect(separators).toHaveLength(1);- expect(separators[0].previousElementSibling).toBe(suggestions[1]);- expect(separators[0].nextElementSibling?.querySelector(".bx-search")).not.toBeNull();+ // The list holds the notes alone.+ expect(getNoteSuggestions).toHaveBeenLastCalledWith("al", expect.objectContaining({ allowJumpToSearchNotes: false }));+ expect(host.querySelectorAll(".note-suggestion-list > .dropdown-item")).toHaveLength(2);+ expect(host.querySelector(".note-suggestion-list > .dropdown-divider")).toBeNull();++ // A switch under the list searches the contents, and stays on as the query changes.+ const contentsSwitch = () => host.querySelector<HTMLInputElement>(".note-suggestion-footer input.switch-toggle");+ expect(contentsSwitch()?.checked).toBe(false);+ await act(async () => { contentsSwitch()?.dispatchEvent(new Event("input", { bubbles: true })); });+ await settle();+ expect(contentsSwitch()?.checked).toBe(true);+ expect(getNoteSuggestions).toHaveBeenLastCalledWith("al", expect.objectContaining({ fastSearch: false }));+ await type(input, "alp");+ expect(getNoteSuggestions).toHaveBeenLastCalledWith("alp", expect.objectContaining({ fastSearch: false }));+ await press(input, "Enter", { shiftKey: true });+ expect(contentsSwitch()?.checked).toBe(false);+ expect(getNoteSuggestions.mock.lastCall?.[1]?.fastSearch).toBeUndefined();+ expect(document.activeElement).toBe(input);++ // The footer under the list opens the full search, reported for the host to close on.+ const footer = host.querySelector<HTMLButtonElement>(".note-suggestion-footer button.btn");+ await act(async () => { footer?.click(); });+ expect(triggerCommand).toHaveBeenCalledWith("searchNotes", { searchString: "alp" });+ expect(onChange).toHaveBeenLastCalledWith({ action: "search-notes", noteTitle: "alp" });host.remove();++ // A dropdown keeps its content search row and has no footer.+ const popupInput = await mount();+ await type(popupInput, "al");+ expect(fullTextRow()).toBeDefined();+ expect(document.querySelector(".note-suggestion-footer")).toBeNull();});it("runs a search from its row, with its shortcut shown, reporting it for the host to close on", async () => {diff --git a/apps/client/src/widgets/react/NoteAutocomplete.tsx b/apps/client/src/widgets/react/NoteAutocomplete.tsxindex 275094d2de..3b6e9a55fd 100644--- a/apps/client/src/widgets/react/NoteAutocomplete.tsx+++ b/apps/client/src/widgets/react/NoteAutocomplete.tsx@@ -13,8 +13,10 @@ import { t } from "../../services/i18n";import { createSearchScheduler, createNoteFromSuggestion, getCommandSuggestions, getNoteSuggestions, type Options, type Suggestion } from "../../services/note_autocomplete";import { escapeHtml, isMobile } from "../../services/utils";import { AttributeSnippetBadges } from "./Badge";+import Button from "./Button";import { useAutocomplete } from "./FormAutocomplete";import { FormDropdownDivider } from "./FormList";+import FormToggle from "./FormToggle";import { useSyncedRef } from "./hooks";import Icon from "./Icon";import Popup from "./Popup";@@ -75,6 +77,10 @@ export default function NoteAutocomplete({ id, inputRef: externalInputRef, text,// one changes `source` and so searches again.const [ fullTextSearchCount, setFullTextSearchCount ] = useState(0);const [ isSearchingFullText, setSearchingFullText ] = useState(false);+ // A list in a host's container offers its searches in a footer under it: a switch for the content+ // search, which stays on as the query changes, and a button for the full search.+ const isContained = !!container;+ const [ includeContents, setIncludeContents ] = useState(false);const { isCommandPalette, allowCreatingNotes, allowJumpToSearchNotes, allowExternalLinks } = opts ?? {};const source = useCallback(async (query: string) => {@@ -82,7 +88,14 @@ export default function NoteAutocomplete({ id, inputRef: externalInputRef, text,return getCommandSuggestions(query);}- const options = { allowCreatingNotes, allowJumpToSearchNotes, allowExternalLinks };+ const options = {+ allowCreatingNotes,+ allowJumpToSearchNotes: allowJumpToSearchNotes && !isContained,+ allowExternalLinks+ };+ if (isContained) {+ return getNoteSuggestions(query, includeContents ? { ...options, fastSearch: false } : options);+ }if (!fullTextSearchCount) {return withFullTextSearchRow(await getNoteSuggestions(query, options), query);}@@ -93,7 +106,10 @@ export default function NoteAutocomplete({ id, inputRef: externalInputRef, text,} finally {setSearchingFullText(false);}- }, [ isCommandPalette, allowCreatingNotes, allowJumpToSearchNotes, allowExternalLinks, fullTextSearchCount ]);+ }, [+ isCommandPalette, allowCreatingNotes, allowJumpToSearchNotes, allowExternalLinks, fullTextSearchCount,+ isContained, includeContents+ ]);const schedule = useMemo(() => createSearchScheduler(), []);const selectNote = useCallback((suggestion: Suggestion) => {@@ -164,6 +180,11 @@ export default function NoteAutocomplete({ id, inputRef: externalInputRef, text,clearSelection();}+ /** Whether `query` is one to open the full search on: a non-blank query naming notes, not commands. */+ function canSearchFor(query: string) {+ return !!query.trim() && !(isCommandPalette && query.startsWith(">"));+ }+/*** Opens the search screen on `searchString`, and reports it as a picked `search-notes` row so that* a host can close, as Jump to Note does.@@ -173,8 +194,17 @@ export default function NoteAutocomplete({ id, inputRef: externalInputRef, text,onChange?.({ action: "search-notes", noteTitle: searchString });}- /** Searches the content of the notes as well as their titles, for the text in the field. */+ /**+ * Searches the content of the notes as well as their titles, for the text in the field. A list in a+ * host's container switches its content search on or off instead.+ */function fullTextSearch() {+ if (isContained) {+ setIncludeContents((include) => !include);+ autocomplete.open();+ inputRef.current?.focus();+ return;+ }if (!value.trim()) return;setNotePath("");setFullTextSearchCount((count) => count + 1);@@ -264,8 +294,8 @@ export default function NoteAutocomplete({ id, inputRef: externalInputRef, text,// own.e.preventDefault();e.stopImmediatePropagation();- // Only where the list offers the row: a query that names notes, not commands.- if (value.trim() && !(isCommandPalette && value.startsWith(">"))) {+ // Only where the list offers it: a query that names notes, not commands.+ if (canSearchFor(value)) {showInFullSearch(value.trim());}return;@@ -320,15 +350,40 @@ export default function NoteAutocomplete({ id, inputRef: externalInputRef, text,</>}{(autocomplete.isShown || (autocomplete.isOpen && isSearchingFullText)) && (container- ? container.current && createPortal(+ ? container.current && createPortal(<><NoteSuggestionMenuautocomplete={autocomplete}searchingFor={isSearchingFullText ? value : undefined}// The popup's rows, in the host's panel. Faded at an edge only where the host// sets `--scroll-fade-top` or `--scroll-fade-bottom`.className="note-autocomplete-menu note-suggestion-list tn-menu-keyboard scroll-edge-fade"- />,- container.current)+ />+ {canSearchFor(value) && (+ <div+ className="note-suggestion-footer"+ // Keeps the focus in the field, as the rows do.+ onMouseDown={(e) => e.preventDefault()}+ >+ <FormToggle+ switchOnName={t("note_autocomplete.include-contents")}+ switchOffName={t("note_autocomplete.include-contents")}+ currentValue={includeContents}+ onChange={fullTextSearch}+ afterName={!cachedIsMobile && (+ <span className="note-suggestion-shortcut">{renderShortcutKbds("Shift+Enter")}</span>+ )}+ />+ {allowJumpToSearchNotes && <Button+ kind="lowProfile"+ size="small"+ icon="bx-file-find"+ text={t("quick-search.show-in-full-search")}+ keyboardShortcut="Ctrl+Enter"+ onClick={() => showInFullSearch(value.trim())}+ />}+ </div>+ )}+ </>, container.current): anchor && (<Popupanchor={anchor}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 e0d4ee77e0..5f8bd4afb2 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@@ -35,24 +35,25 @@<li><em>Create child note</em> places it under the note that is currently open.</li></ul></li>- <li>When the title search does not find a note, the two options at the end- of the list search further:+ <li>When the title search does not find a note, the bar below the results+ offers two ways to search further. It stays below the list, however far+ the results are scrolled.<ul>- <li><em>Include note contents in the results</em> 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.</li>- <li><em>Show all results in full search</em> opens the query in the full <a- class="reference-link" href="#root/_help_eIg8jdvaoNNd">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.</li>+ <li>The <em>Include note contents</em> switch 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. It stays on while the query changes,+ until it is switched off. Press <kbd>Shift</kbd>+<kbd>Enter</kbd> to switch+ it from the keyboard.</li>+ <li><em>Show in full search</em> opens the query in the full <a class="reference-link"+ href="#root/_help_eIg8jdvaoNNd">Search</a>, in a new tab, where its options+ can refine it. Press <kbd>Ctrl</kbd>+<kbd>Enter</kbd> to run it from the+ keyboard.</li></ul></li>- <li>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.</li>+ <li>The options to create a note are listed after the notes. 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/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.htmlindex f181a8713c..5fc171bb8c 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.html@@ -55,7 +55,8 @@the <a class="reference-link" href="#root/_help_YtSN43OrfzaA">Note tree contextual menu</a> orpress <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>S</kbd>.</li><li>Go to <a class="reference-link" href="#root/_help_F1r9QtzQLZqm">Jump to & command palette</a>,- look for something then press <em>Search in full text</em> (or <kbd>Ctrl</kbd>+<kbd>Enter</kbd>).</li>+ look for something then press <em>Show in full search</em> below the results+ (or <kbd>Ctrl</kbd>+<kbd>Enter</kbd>).</li></ul><h2>Interaction</h2><p>To search for notes, click on the magnifying glass icon on the toolbardiff --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 f6988d8963..9747336289 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@@ -19,10 +19,10 @@ In addition to searching for notes, it is also possible to search for commands.* If the note doesn't exist, it's possible to create it by typing the desired note title and selecting one of two options:* _Create note_ places it in the <a class="reference-link" href="../Notes/Note%20Inbox.md">Note Inbox</a>: the note labelled `#inbox`, today's <a class="reference-link" href="../../Advanced%20Usage/Advanced%20Showcases/Day%20Notes.md">Day Notes</a> if there is none, or the top level if there is no journal either. While hoisted into a <a class="reference-link" href="Workspaces.md">Workspaces</a>, the workspace's own inbox is used, then today's day note if the workspace has a `#workspaceCalendarRoot`, otherwise the workspace root itself. The option names the destination, so it is always visible before the note is created.* _Create child note_ places it under the note that is currently open.-* 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. 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.+* When the title search does not find a note, the bar below the results offers two ways to search further. It stays below the list, however far the results are scrolled.+ * The _Include note contents_ switch 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. It stays on while the query changes, until it is switched off. Press <kbd>Shift</kbd>+<kbd>Enter</kbd> to switch it from the keyboard.+ * _Show 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 from the keyboard.+* The options to create a note are listed after the notes. 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 notesdiff --git a/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.md b/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.mdindex 7357d57fa8..3374ff06e9 100644--- a/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.md+++ b/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Search.md@@ -26,7 +26,7 @@ There are multiple types of searches, all using the same search mechanism and qu* From the <a class="reference-link" href="../UI%20Elements/Launch%20Bar.md">Launch Bar</a>, look for the dedicated search button.* To limit the search to a note and its children, select _Search from subtree_ from the <a class="reference-link" href="../UI%20Elements/Note%20Tree/Note%20tree%20contextual%20menu.md">Note tree contextual menu</a> or press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>S</kbd>.-* Go to <a class="reference-link" href="Jump%20to%20%26%20command%20palette.md">Jump to & command palette</a>, look for something then press _Search in full text_ (or <kbd>Ctrl</kbd>+<kbd>Enter</kbd>).+* Go to <a class="reference-link" href="Jump%20to%20%26%20command%20palette.md">Jump to & command palette</a>, look for something then press _Show in full search_ below the results (or <kbd>Ctrl</kbd>+<kbd>Enter</kbd>).## Interaction