Skip to content

Build your personal knowledge base with Trilium Notes

refactor(jump-to-note): open the full search from the list alone

Elian Doran936a78a1cf3a
diff --git a/apps/client/src/services/note_autocomplete.spec.ts b/apps/client/src/services/note_autocomplete.spec.ts
index defe0c562a..d905e94485 100644
--- a/apps/client/src/services/note_autocomplete.spec.ts
+++ b/apps/client/src/services/note_autocomplete.spec.ts
@@ -148,7 +148,7 @@ describe("getNoteSuggestions", () => {
const rows = await getNoteSuggestions("https://example.com/x", all);
expect(rows.map((r) => r.action)).toEqual([ "external-link", "create-note", "create-child-note", undefined, "search-notes" ]);
expect(rows[0]).toMatchObject({ externalLink: "https://example.com/x", highlightedNotePathTitle: "note_autocomplete.insert-external-link" });
- expect(rows[4]).toMatchObject({ noteTitle: "https://example.com/x", highlightedNotePathTitle: "note_autocomplete.search-for" });
+ expect(rows[4]).toMatchObject({ noteTitle: "https://example.com/x", highlightedNotePathTitle: "note_autocomplete.show-in-full-search" });
// Not a URL, and a blank term: neither row is offered.
expect((await getNoteSuggestions("plain", all)).map((r) => r.action)).not.toContain("external-link");
diff --git a/apps/client/src/services/note_autocomplete.ts b/apps/client/src/services/note_autocomplete.ts
index 0800211d97..f6a99c16ef 100644
--- a/apps/client/src/services/note_autocomplete.ts
+++ b/apps/client/src/services/note_autocomplete.ts
@@ -114,7 +114,7 @@ export async function getNoteSuggestions(term: string, { allowCreatingNotes, all
after.push({
action: "search-notes",
noteTitle: term,
- highlightedNotePathTitle: t("note_autocomplete.search-for", { term: escapeHtml(term) })
+ highlightedNotePathTitle: t("note_autocomplete.show-in-full-search", { term: escapeHtml(term) })
});
}
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 6a7f528dd0..e4a777af4f 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -349,8 +349,7 @@
"copy_to_clipboard": "Copy to clipboard"
},
"jump_to_note": {
- "search_placeholder": "Search for note by its name or type > for commands...",
- "search_button": "Search in full text"
+ "search_placeholder": "Search for note by its name or type > for commands..."
},
"markdown_editor": {
"image_upload_failed": "Cannot upload image \"{{name}}\"."
@@ -3074,7 +3073,7 @@
"zoom-factor": "Zoom factor"
},
"note_autocomplete": {
- "search-for": "Search for \"{{term}}\"",
+ "show-in-full-search": "Show all results for \"{{term}}\" in full search",
"create-note": "Create note \"{{term}}\"",
"create-note-into": "Create note \"{{term}}\" in {{parentTitle}}",
"create-note-into-day-note": "Create note \"{{term}}\" in today's day note",
@@ -3082,7 +3081,7 @@
"create-child-note": "Create child note \"{{term}}\"",
"insert-external-link": "Insert external link to \"{{term}}\"",
"clear-text-field": "Clear text field",
- "search-note-contents": "Search note contents for \"{{term}}\""
+ "include-note-contents": "Include note contents in the results for \"{{term}}\""
},
"note_tooltip": {
"note-has-been-deleted": "Note has been deleted.",
diff --git a/apps/client/src/widgets/dialogs/jump_to_note.css b/apps/client/src/widgets/dialogs/jump_to_note.css
index 0af051ceda..2ae73e11f3 100644
--- a/apps/client/src/widgets/dialogs/jump_to_note.css
+++ b/apps/client/src/widgets/dialogs/jump_to_note.css
@@ -53,12 +53,6 @@
background-color: transparent;
}
-.jump-to-note-dialog .show-in-full-search,
-.jump-to-note-results .show-in-full-search {
- border-top: 1px solid var(--main-border-color);
- padding-top: 12px;
- margin-top: 12px;
-}
.jump-to-note-results .aa-suggestion .search-notes-action {
border-top: 1px solid var(--main-border-color);
diff --git a/apps/client/src/widgets/dialogs/jump_to_note.tsx b/apps/client/src/widgets/dialogs/jump_to_note.tsx
index c16cc5eb3e..ccb52a0fbf 100644
--- a/apps/client/src/widgets/dialogs/jump_to_note.tsx
+++ b/apps/client/src/widgets/dialogs/jump_to_note.tsx
@@ -6,8 +6,6 @@ import appContext from "../../components/app_context";
import commandRegistry from "../../services/command_registry";
import { t } from "../../services/i18n";
import type { Suggestion } from "../../services/note_autocomplete";
-import shortcutService from "../../services/shortcuts";
-import Button from "../react/Button";
import { useTriliumEvent } from "../react/hooks";
import Modal from "../react/Modal";
import NoteAutocomplete, { type NoteAutocompleteHandle } from "../react/NoteAutocomplete";
@@ -23,8 +21,7 @@ export default function JumpToNoteDialogComponent() {
const containerRef = useRef<HTMLDivElement>(null);
const autocompleteRef = useRef<HTMLInputElement>(null);
const handleRef = useRef<NoteAutocompleteHandle>(null);
- const [ isCommandMode, setIsCommandMode ] = useState(mode === "commands");
- const [ initialText, setInitialText ] = useState(isCommandMode ? "> " : "");
+ const [ initialText, setInitialText ] = useState("");
const actualText = useRef<string>(initialText);
const [ shown, setShown ] = useState(false);
@@ -50,10 +47,6 @@ export default function JumpToNoteDialogComponent() {
setMode(newMode);
}
- // `showInFullSearch` reads this ref, so it has to follow the text about to be displayed
- // rather than keep the previous session's query.
- actualText.current = initialText;
-
setInitialText(initialText);
setShown(true);
setLastOpenedTs(Date.now());
@@ -101,27 +94,6 @@ export default function JumpToNoteDialogComponent() {
} else {
$autoComplete.trigger("select");
}
-
- // Add keyboard shortcut for full search
- shortcutService.bindElShortcut($autoComplete, "ctrl+return", () => {
- if (!isCommandMode) {
- showInFullSearch();
- }
- });
- }
-
- async function showInFullSearch() {
- try {
- setShown(false);
- const searchString = actualText.current?.trim();
- if (searchString && !searchString.startsWith(">")) {
- await appContext.triggerCommand("searchNotes", {
- searchString
- });
- }
- } catch (error) {
- console.error("Failed to trigger full search:", error);
- }
}
return (
@@ -140,20 +112,11 @@ export default function JumpToNoteDialogComponent() {
allowJumpToSearchNotes: true,
isCommandPalette: true
}}
- onTextChange={(text) => {
- actualText.current = text;
- setIsCommandMode(text.startsWith(">"));
- }}
+ onTextChange={(text) => actualText.current = text}
onChange={onItemSelected}
/>}
onShown={onShown}
onHidden={() => setShown(false)}
- footer={!isCommandMode && <Button
- className="show-in-full-text-button"
- text={t("jump_to_note.search_button")}
- keyboardShortcut="Ctrl+Enter"
- onClick={showInFullSearch}
- />}
show={shown}
>
<div className="algolia-autocomplete-container jump-to-note-results" ref={containerRef} />
diff --git a/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx b/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx
index 5cbaa97a54..ca9a7f77ce 100644
--- a/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx
+++ b/apps/client/src/widgets/react/NoteAutocomplete.spec.tsx
@@ -236,7 +236,7 @@ describe("NoteAutocomplete's suggestion list", () => {
await type(input, "x");
expect(rows().map((row) => row.querySelector(".tn-icon")?.className)).toEqual([
- "bx bx-search tn-icon", "bx bx-plus tn-icon", "bx bx-subdirectory-right tn-icon", "bx bx-link-external tn-icon", "bx bx-note tn-icon"
+ "bx bx-file-find tn-icon", "bx bx-plus tn-icon", "bx bx-subdirectory-right tn-icon", "bx bx-link-external tn-icon", "bx bx-note tn-icon"
]);
expect(rows()[4].textContent).toBe("T");
});
@@ -664,7 +664,7 @@ describe("NoteAutocomplete's suggestion list", () => {
expect(dividers[0].nextElementSibling).toBe(fullTextRow());
});
- it("runs a search from its row, with its shortcut shown, leaving the field", async () => {
+ 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 ]);
const input = await mount({ onChange });
@@ -677,18 +677,29 @@ describe("NoteAutocomplete's suggestion list", () => {
await press(input, "ArrowDown");
await press(input, "Enter");
expect(triggerCommand).toHaveBeenCalledWith("searchNotes", { searchString: "al" });
- expect(onChange).not.toHaveBeenCalled();
+ expect(onChange).toHaveBeenCalledWith({ action: "search-notes", noteTitle: "al" });
expect(input.value).toBe("al");
});
it("runs a search on Ctrl+Enter where allowed, keeping the key from other listeners", async () => {
- const input = await mount({ opts: { allowJumpToSearchNotes: true } });
- await type(input, "al");
+ const onChange = vi.fn();
+ const input = await mount({ onChange, opts: { allowJumpToSearchNotes: true, isCommandPalette: true } });
+ await type(input, " al ");
const laterListener = vi.fn();
input.addEventListener("keydown", laterListener);
await press(input, "Enter", { ctrlKey: true });
expect(triggerCommand).toHaveBeenCalledWith("searchNotes", { searchString: "al" });
+ expect(onChange).toHaveBeenCalledWith({ action: "search-notes", noteTitle: "al" });
+ expect(laterListener).not.toHaveBeenCalled();
+
+ // Nothing to search for in a blank field or a command query, though the key is still kept.
+ triggerCommand.mockClear();
+ for (const text of [ " ", "> cmd" ]) {
+ await type(input, text);
+ await press(input, "Enter", { ctrlKey: true });
+ }
+ expect(triggerCommand).not.toHaveBeenCalled();
expect(laterListener).not.toHaveBeenCalled();
triggerCommand.mockClear();
diff --git a/apps/client/src/widgets/react/NoteAutocomplete.tsx b/apps/client/src/widgets/react/NoteAutocomplete.tsx
index 90a10768b5..c0cbcb6522 100644
--- a/apps/client/src/widgets/react/NoteAutocomplete.tsx
+++ b/apps/client/src/widgets/react/NoteAutocomplete.tsx
@@ -1,6 +1,7 @@
import "./Menu.css";
import "./NoteAutocomplete.css";
+import { NOTE_TYPE_ICONS } from "@triliumnext/commons";
import clsx from "clsx";
import { type RefObject, render } from "preact";
import { createPortal, type CSSProperties, Fragment } from "preact/compat";
@@ -107,7 +108,7 @@ export default function NoteAutocomplete({ id, inputRef: externalInputRef, text,
onChange?.(suggestion);
break;
case "search-notes":
- void appContext.triggerCommand("searchNotes", { searchString: suggestion.noteTitle });
+ showInFullSearch(suggestion.noteTitle ?? "");
break;
case "full-text-search":
fullTextSearch();
@@ -158,6 +159,15 @@ export default function NoteAutocomplete({ id, inputRef: externalInputRef, text,
clearSelection();
}
+ /**
+ * 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.
+ */
+ function showInFullSearch(searchString: string) {
+ void appContext.triggerCommand("searchNotes", { searchString });
+ onChange?.({ action: "search-notes", noteTitle: searchString });
+ }
+
/** Searches the content of the notes as well as their titles, for the text in the field. */
function fullTextSearch() {
if (!value.trim()) return;
@@ -249,7 +259,10 @@ export default function NoteAutocomplete({ id, inputRef: externalInputRef, text,
// own.
e.preventDefault();
e.stopImmediatePropagation();
- void appContext.triggerCommand("searchNotes", { searchString: value });
+ // Only where the list offers the row: a query that names notes, not commands.
+ if (value.trim() && !(isCommandPalette && value.startsWith(">"))) {
+ showInFullSearch(value.trim());
+ }
return;
}
if (isEnter && e.shiftKey) {
@@ -480,7 +493,8 @@ function isSearchRow(suggestion: Suggestion) {
function suggestionIcon(suggestion: Suggestion) {
switch (suggestion.action) {
- case "search-notes": return "bx bx-search";
+ // The icon of the saved search note it opens.
+ case "search-notes": return NOTE_TYPE_ICONS.search;
case "full-text-search": return "bx bx-search";
case "create-note": return "bx bx-plus";
case "create-child-note": return "bx bx-subdirectory-right";
@@ -508,7 +522,7 @@ function withFullTextSearchRow(rows: Suggestion[], query: string): Suggestion[]
const row: Suggestion = {
action: "full-text-search",
noteTitle: query,
- highlightedNotePathTitle: t("note_autocomplete.search-note-contents", { term: escapeHtml(query) })
+ highlightedNotePathTitle: t("note_autocomplete.include-note-contents", { term: escapeHtml(query) })
};
const last = rows.at(-1);
return last?.action === "search-notes" ? [ ...rows.slice(0, -1), row, last ] : [ ...rows, row ];
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.html
index 7b3a19980c..e832af9a64 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,6 +35,19 @@
<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:
+ <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>
+ </ul>
+ </li>
</ul>
<h2>Recent notes</h2>
<p>Jump to note also has the ability to show the list of recently viewed
@@ -42,7 +55,6 @@
<p>To access this functionality, click on <code>Jump to</code> button on the
top. By default, (when nothing is entered into autocomplete), this dialog
will show the list of recent notes.</p>
-<p>Alternatively you can click on the "time" icon on the right.</p>
<h2>Command Palette</h2>
<figure class="image image-style-align-center">
<img style="aspect-ratio:982/524;" src="Jump to & command palette_image.png"
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Presentation.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Presentation.html
index 4f1af11c44..a0db7eb0a3 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Presentation.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Presentation.html
@@ -135,4 +135,4 @@ config:
</ul>
<h2>Under the hood</h2>
<p>The Presentation view uses <a href="https://revealjs.com/">Reveal.js</a> to
- handle the navigation and layout of the slides.</p>
+ handle the navigation and layout of the slides.</p>
\ No newline at end of file
diff --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.md
index 066a13c450..275ca33e7c 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,6 +19,9 @@ 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.
## Recent notes
@@ -26,8 +29,6 @@ Jump to note also has the ability to show the list of recently viewed / edited n
To access this functionality, click on `Jump to` button on the top. By default, (when nothing is entered into autocomplete), this dialog will show the list of recent notes.
-Alternatively you can click on the "time" icon on the right.
-
## Command Palette
<figure class="image image-style-align-center"><img style="aspect-ratio:982/524;" src="Jump to &amp; command palette_image.png" width="982" height="524"></figure>
diff --git a/docs/User Guide/User Guide/Collections/Presentation.md b/docs/User Guide/User Guide/Collections/Presentation.md
index 4a1157e0bb..97891a7826 100644
--- a/docs/User Guide/User Guide/Collections/Presentation.md
+++ b/docs/User Guide/User Guide/Collections/Presentation.md
@@ -86,4 +86,4 @@ At slide level:
## Under the hood
-The Presentation view uses [Reveal.js](https://revealjs.com/) to handle the navigation and layout of the slides.
+The Presentation view uses [Reveal.js](https://revealjs.com/) to handle the navigation and layout of the slides.
\ No newline at end of file