Skip to content

Build your personal knowledge base with Trilium Notes

fix(jump-to-note): leave the preview out of the command palette

Elian Doran1a15a74d2253
diff --git a/apps/client/src/widgets/dialogs/jump_to_note.css b/apps/client/src/widgets/dialogs/jump_to_note.css
index 647d2dd41f..36ba670b3e 100644
--- a/apps/client/src/widgets/dialogs/jump_to_note.css
+++ b/apps/client/src/widgets/dialogs/jump_to_note.css
@@ -55,42 +55,46 @@ body.desktop .jump-to-note-results {
}
/*
- * Room for a preview beside the results: the dialog widens into two columns, the results and the
- * preview, with the footer across both. Matches `PREVIEW_MEDIA_QUERY` in jump_to_note.tsx. The
- * results' container steps aside (`display: contents`), so its list and footer take the grid's cells.
+ * Where the window has room for a preview (`wide`, set by jump_to_note.tsx), the dialog takes its
+ * width whether or not the preview shows, and lays its body out as a grid: the results, the preview
+ * beside them while `with-preview` is set, and the footer across the full width. The results'
+ * container steps aside (`display: contents`), so its list and footer take the grid's cells.
*/
-@media (min-width: 1100px) {
- body.desktop .jump-to-note-dialog {
- .modal-dialog {
- max-width: 1200px;
- }
+body.desktop .jump-to-note-dialog.wide {
+ .modal-dialog {
+ max-width: 1200px;
+ }
- .modal-body {
- display: grid;
- grid-template-columns: minmax(0, 1fr) 400px;
- grid-template-rows: minmax(0, 1fr) auto;
- column-gap: 16px;
- height: calc(80vh - 150px);
- }
+ .modal-body {
+ display: grid;
+ grid-template-columns: minmax(0, 1fr);
+ grid-template-rows: minmax(0, 1fr) auto;
+ column-gap: 16px;
+ height: calc(80vh - 150px);
+ }
- .jump-to-note-results {
- display: contents;
- }
+ .jump-to-note-results {
+ display: contents;
+ }
- .jump-to-note-results .note-suggestion-list {
- grid-area: 1 / 1;
- margin-inline-end: 0;
- }
+ .jump-to-note-results .note-suggestion-list {
+ grid-area: 1 / 1;
+ margin-inline-end: 0;
+ }
- .jump-to-note-results .note-suggestion-footer {
- grid-area: 2 / 1 / 3 / 3;
- }
+ .jump-to-note-results .note-suggestion-footer {
+ grid-row: 2;
+ grid-column: 1 / -1;
+ }
- .jump-to-note-preview {
- grid-area: 1 / 2;
- min-height: 0;
- padding-block: 8px;
- }
+ .jump-to-note-preview {
+ grid-area: 1 / 2;
+ min-height: 0;
+ padding-block: 8px;
+ }
+
+ &.with-preview .modal-body {
+ grid-template-columns: minmax(0, 1fr) 400px;
}
}
diff --git a/apps/client/src/widgets/dialogs/jump_to_note.spec.tsx b/apps/client/src/widgets/dialogs/jump_to_note.spec.tsx
index 2d254aa8fe..1eea7780bd 100644
--- a/apps/client/src/widgets/dialogs/jump_to_note.spec.tsx
+++ b/apps/client/src/widgets/dialogs/jump_to_note.spec.tsx
@@ -2,6 +2,16 @@ import { act } from "preact/test-utils";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
const noteContent = vi.hoisted(() => ({ rendered: [] as string[] }));
+const autocomplete = vi.hoisted(() => ({
+ onTextChange: undefined as ((text: string) => void) | undefined
+}));
+
+vi.mock("../react/NoteAutocomplete", () => ({
+ default: ({ onTextChange }: { onTextChange: (text: string) => void }) => {
+ autocomplete.onTextChange = onTextChange;
+ return <input />;
+ }
+}));
vi.mock("../collections/legacy/ListOrGridView", () => ({
NoteContent: ({ note }: { note: { noteId: string } }) => {
@@ -11,10 +21,12 @@ vi.mock("../collections/legacy/ListOrGridView", () => ({
NoteAttributes: () => <span className="stub-attributes" />
}));
+import Component from "../../components/component";
import type { Suggestion } from "../../services/note_autocomplete";
import { buildNote } from "../../test/easy-froca";
import { renderInto } from "../../test/render";
-import { JumpToNotePreview, PREVIEW_DELAY_MS } from "./jump_to_note";
+import { ParentComponent } from "../react/react_utils";
+import JumpToNoteDialog, { JumpToNotePreview, PREVIEW_DELAY_MS } from "./jump_to_note";
describe("JumpToNotePreview", () => {
beforeEach(() => {
@@ -68,3 +80,28 @@ describe("JumpToNotePreview", () => {
}
});
});
+
+describe("JumpToNoteDialog's preview", () => {
+ it("is left out for the command palette, and back once the query names notes again, the dialog keeping its width", async () => {
+ vi.spyOn(window, "matchMedia").mockReturnValue({
+ matches: true, addEventListener() {}, removeEventListener() {}
+ } as unknown as MediaQueryList);
+ const host = new Component();
+ const container = renderInto(
+ <ParentComponent.Provider value={host}><JumpToNoteDialog /></ParentComponent.Provider>
+ );
+ await act(async () => { void host.handleEventInChildren("commandPalette", {}); });
+ await act(async () => { autocomplete.onTextChange?.(">"); });
+
+ const dialog = () => container.querySelector(".jump-to-note-dialog");
+ expect(container.querySelector(".jump-to-note-preview")).toBeNull();
+ expect(dialog()?.classList.contains("with-preview")).toBe(false);
+ expect(dialog()?.classList.contains("wide")).toBe(true);
+
+ await act(async () => { autocomplete.onTextChange?.("plan"); });
+ expect(container.querySelector(".jump-to-note-preview")).not.toBeNull();
+ expect(dialog()?.classList.contains("with-preview")).toBe(true);
+ expect(dialog()?.classList.contains("wide")).toBe(true);
+ vi.restoreAllMocks();
+ });
+});
diff --git a/apps/client/src/widgets/dialogs/jump_to_note.tsx b/apps/client/src/widgets/dialogs/jump_to_note.tsx
index 26e0216897..da1d06c22a 100644
--- a/apps/client/src/widgets/dialogs/jump_to_note.tsx
+++ b/apps/client/src/widgets/dialogs/jump_to_note.tsx
@@ -1,5 +1,6 @@
import "./jump_to_note.css";
+import clsx from "clsx";
import { useEffect, useRef, useState } from "preact/hooks";
import appContext from "../../components/app_context";
@@ -19,7 +20,7 @@ import { refToJQuerySelector } from "../react/react_utils";
const KEEP_LAST_SEARCH_FOR_X_SECONDS = 120;
/** How long the highlight rests on a row before the preview renders it, so arrowing past skips it. */
export const PREVIEW_DELAY_MS = 150;
-/** Wide enough for the results and the preview side by side; matches the media query in jump_to_note.css. */
+/** Wide enough for the results and the preview side by side. */
const PREVIEW_MEDIA_QUERY = "(min-width: 1100px)";
type Mode = "last-search" | "recent-notes" | "commands";
@@ -34,7 +35,12 @@ export default function JumpToNoteDialogComponent() {
const actualText = useRef<string>(initialText);
const [ shown, setShown ] = useState(false);
const [ highlighted, setHighlighted ] = useState<Suggestion>();
- const showsPreview = useMediaQuery(PREVIEW_MEDIA_QUERY) && !isMobile();
+ // The command palette lists commands, which have no content to preview.
+ const [ isCommandQuery, setCommandQuery ] = useState(false);
+ // The dialog keeps the preview's width while the command palette leaves it out, so it does not
+ // resize as `>` is typed and erased.
+ const isWide = useMediaQuery(PREVIEW_MEDIA_QUERY) && !isMobile();
+ const showsPreview = isWide && !isCommandQuery;
async function openDialog(commandMode: boolean) {
let newMode: Mode;
@@ -109,7 +115,7 @@ export default function JumpToNoteDialogComponent() {
return (
<Modal
- className="jump-to-note-dialog"
+ className={clsx("jump-to-note-dialog", isWide && "wide", showsPreview && "with-preview")}
size="lg"
title={<>
{!isMobile() && <Icon icon="bx bx-search" className="jump-to-note-search-icon" />}
@@ -125,7 +131,10 @@ export default function JumpToNoteDialogComponent() {
allowJumpToSearchNotes: true,
isCommandPalette: true
}}
- onTextChange={(text) => actualText.current = text}
+ onTextChange={(text) => {
+ actualText.current = text;
+ setCommandQuery(text.startsWith(">"));
+ }}
onChange={onItemSelected}
searchFooter
onHighlight={showsPreview ? setHighlighted : undefined}
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 61d3814d67..b25d39591a 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
@@ -57,7 +57,7 @@
<li>On a wide enough desktop window, the note highlighted in the results is
previewed on their right: its path, title, attributes and the start of
its content. The preview follows the highlight as it moves through the
- results.</li>
+ results, and is left out for the command palette.</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
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 671e7cb180..c39ab4c15f 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
@@ -23,7 +23,7 @@ In addition to searching for notes, it is also possible to search for commands.
* 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.
* To see the keys the results answer to, click the <kbd>?</kbd> button below the results, or press <kbd>Alt</kbd>+<kbd>F1</kbd> while the search field is focused.
-* On a wide enough desktop window, the note highlighted in the results is previewed on their right: its path, title, attributes and the start of its content. The preview follows the highlight as it moves through the results.
+* On a wide enough desktop window, the note highlighted in the results is previewed on their right: its path, title, attributes and the start of its content. The preview follows the highlight as it moves through the results, and is left out for the command palette.
* 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 notes