Skip to content

Build your personal knowledge base with Trilium Notes

feat(client): content snippets in jump-to-note dialog

perfectra1n0dc1e8ceb903
diff --git a/apps/client/src/services/note_autocomplete.spec.ts b/apps/client/src/services/note_autocomplete.spec.ts
index 23b6ca325b..2783f393a1 100644
--- a/apps/client/src/services/note_autocomplete.spec.ts
+++ b/apps/client/src/services/note_autocomplete.spec.ts
@@ -337,6 +337,34 @@ describe("autocompleteSource (via dataset)", () => {
expect(html).toContain("#color=red");
});
+ it("does not render a content snippet by default, even when the suggestion has one", () => {
+ // showContentSnippets defaults to false so compact consumers (link dialogs, relation
+ // editors, @-mentions) don't grow an extra line.
+ const { dataset } = initAndGetSource();
+ const html = dataset.templates.suggestion({
+ highlightedNotePathTitle: "T",
+ highlightedContentSnippet: "some <b>matched</b> content"
+ });
+ expect(html).not.toContain("search-result-content");
+ expect(html).not.toContain("matched");
+ });
+
+ it("does not render a content snippet when showContentSnippets is set but the suggestion has none", () => {
+ const { dataset } = initAndGetSource({ showContentSnippets: true });
+ const html = dataset.templates.suggestion({ highlightedNotePathTitle: "T" });
+ expect(html).not.toContain("search-result-content");
+ });
+
+ it("renders the content snippet when showContentSnippets is enabled (jump-to-note dialog)", () => {
+ const { dataset } = initAndGetSource({ showContentSnippets: true });
+ const html = dataset.templates.suggestion({
+ highlightedNotePathTitle: "T",
+ highlightedContentSnippet: "some <b>matched</b> content"
+ });
+ expect(html).toContain("search-result-content");
+ expect(html).toContain("some <b>matched</b> content");
+ });
+
it("renders search-notes, create-note and external-link suggestion icons/classes", () => {
const { dataset } = initAndGetSource();
expect(dataset.templates.suggestion({ action: "search-notes", highlightedNotePathTitle: "S" }))
diff --git a/apps/client/src/services/note_autocomplete.ts b/apps/client/src/services/note_autocomplete.ts
index 4b366a6611..797a357d36 100644
--- a/apps/client/src/services/note_autocomplete.ts
+++ b/apps/client/src/services/note_autocomplete.ts
@@ -40,6 +40,8 @@ export interface Suggestion {
commandShortcut?: string;
attributeSnippet?: string;
highlightedAttributeSnippet?: string;
+ contentSnippet?: string;
+ highlightedContentSnippet?: string;
}
export interface Options {
@@ -54,6 +56,12 @@ export interface Options {
hideAllButtons?: boolean;
/** If set, enables command palette mode */
isCommandPalette?: boolean;
+ /**
+ * If set, note suggestions also render their content snippet (below the attribute
+ * snippet), matching the quick-search dropdown / search results view. Off by default
+ * so compact consumers (link dialogs, relation editors, `@`-mentions) stay unchanged.
+ */
+ showContentSnippets?: boolean;
}
async function autocompleteSourceForCKEditor(queryText: string) {
@@ -364,6 +372,12 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
html += `<span class="search-result-attributes">${suggestion.highlightedAttributeSnippet}</span>`;
}
+ // Add content snippet below, only for consumers that opted in (e.g. the
+ // jump-to-note dialog) — link dialogs/relation editors/`@`-mentions stay compact.
+ if (options.showContentSnippets && suggestion.highlightedContentSnippet) {
+ html += `<span class="search-result-content">${suggestion.highlightedContentSnippet}</span>`;
+ }
+
html += `</span>`;
html += `</div>`;
return html;
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index 333713d90f..376b226458 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -994,6 +994,24 @@ table.promoted-attributes-in-tooltip th {
word-wrap: break-word;
}
+.aa-dropdown-menu .aa-suggestion .search-result-content {
+ display: block;
+ margin-top: 4px;
+ font-size: 0.85em;
+ color: var(--muted-text-color);
+ line-height: 1.3;
+ word-wrap: break-word;
+}
+
+/* Highlight the server-injected <b> tags with the same vars the snippet cards
+ (SearchResultsList.css / ListOrGridView.css) and quick-search dropdown use. */
+.aa-dropdown-menu .aa-suggestion .search-result-content b {
+ background: var(--note-list-view-search-result-highlight-background);
+ color: var(--note-list-view-search-result-highlight-color);
+ font-weight: 600;
+ text-decoration: underline;
+}
+
.aa-dropdown-menu .aa-suggestion p {
padding: 0;
margin: 0;
diff --git a/apps/client/src/widgets/dialogs/jump_to_note.tsx b/apps/client/src/widgets/dialogs/jump_to_note.tsx
index 319fa61955..afe219d994 100644
--- a/apps/client/src/widgets/dialogs/jump_to_note.tsx
+++ b/apps/client/src/widgets/dialogs/jump_to_note.tsx
@@ -5,6 +5,7 @@ import { useRef, useState } from "preact/hooks";
import appContext from "../../components/app_context";
import commandRegistry from "../../services/command_registry";
import { t } from "../../services/i18n";
+import type { ViewScope } from "../../services/link";
import note_autocomplete, { Suggestion } from "../../services/note_autocomplete";
import shortcutService from "../../services/shortcuts";
import Button from "../react/Button";
@@ -64,7 +65,12 @@ export default function JumpToNoteDialogComponent() {
setShown(false);
if (suggestion.notePath) {
- appContext.tabManager.getActiveContext()?.setNote(suggestion.notePath);
+ // Only carry search terms into the opened note when the dialog was actually used
+ // as a text search (not the command palette, and not the empty "recent notes" list) —
+ // jumping from a command or an untyped recent-note pick shouldn't highlight anything.
+ const searchString = !isCommandMode ? actualText.current?.trim() : "";
+ const viewScope: JumpToNoteViewScope = searchString ? { searchTerms: [searchString] } : {};
+ appContext.tabManager.getActiveContext()?.setNote(suggestion.notePath, { viewScope });
} else if (suggestion.commandId) {
await commandRegistry.executeCommand(suggestion.commandId);
}
@@ -132,7 +138,8 @@ export default function JumpToNoteDialogComponent() {
allowCreatingNotes: true,
hideGoToSelectedNoteButton: true,
allowJumpToSearchNotes: true,
- isCommandPalette: true
+ isCommandPalette: true,
+ showContentSnippets: true
}}
onTextChange={(text) => {
actualText.current = text;
@@ -154,3 +161,11 @@ export default function JumpToNoteDialogComponent() {
</Modal>
);
}
+
+/**
+ * Task 8 promotes `searchTerms` onto {@link ViewScope}; widened locally until then (same
+ * pattern as SearchResultCard.tsx's `SearchResultViewScope`). The autocomplete response has
+ * no per-suggestion token list, so we pass the trimmed raw query as a single term rather than
+ * re-deriving a token list client-side — simple, and good enough for jump-to-match highlighting.
+ */
+type JumpToNoteViewScope = ViewScope & { searchTerms?: string[] };