Skip to content

Build your personal knowledge base with Trilium Notes

chore(client): align quick-search highlight styling

perfectra1nc03694bf48b1
diff --git a/apps/client/src/widgets/quick_search.ts b/apps/client/src/widgets/quick_search.ts
index 44d93ad180..e533a87e3e 100644
--- a/apps/client/src/widgets/quick_search.ts
+++ b/apps/client/src/widgets/quick_search.ts
@@ -99,11 +99,15 @@ const TPL = /*html*/`
text-overflow: ellipsis;
}
- /* Search result highlighting */
+ /* Search result highlighting: point at the same highlight vars the snippet cards
+ (SearchResultsList.css / ListOrGridView.css) use, falling back to the pre-existing
+ colors if a theme hasn't defined them. */
.quick-search .search-result-title b,
.quick-search .search-result-content b,
.quick-search .search-result-attributes b {
- color: var(--admonition-warning-accent-color);
+ background: var(--note-list-view-search-result-highlight-background, transparent);
+ color: var(--note-list-view-search-result-highlight-color, var(--admonition-warning-accent-color));
+ font-weight: 600;
text-decoration: underline;
}
@@ -144,6 +148,8 @@ interface QuickSearchResponse {
highlightedAttributeSnippet?: string;
icon: string;
}>;
+ /** Plain search tokens the server highlighted; consumed by jump-to-match producers. */
+ highlightedTokens?: string[];
error: string;
}
@@ -159,6 +165,10 @@ export default class QuickSearchWidget extends BasicWidget {
private currentDisplayedCount: number = 0;
private isLoadingMore: boolean = false;
+ // Plain tokens the server highlighted for the last completed search. Consumed by
+ // jump-to-match producers (Task 9) to know what to highlight in the opened note.
+ private lastHighlightedTokens: string[] = [];
+
doRender() {
this.$widget = $(TPL);
this.$searchString = this.$widget.find(".search-string");
@@ -243,7 +253,9 @@ export default class QuickSearchWidget extends BasicWidget {
${t("quick-search.searching")}
</span>`);
- const { searchResultNoteIds, searchResults, error } = await server.get<QuickSearchResponse>(`quick-search/${encodeURIComponent(searchString)}`);
+ const { searchResultNoteIds, searchResults, highlightedTokens, error } = await server.get<QuickSearchResponse>(`quick-search/${encodeURIComponent(searchString)}`);
+
+ this.lastHighlightedTokens = highlightedTokens || [];
if (error) {
const tooltip = new Tooltip(this.$searchString[0], {
diff --git a/packages/trilium-core/src/routes/api/search.spec.ts b/packages/trilium-core/src/routes/api/search.spec.ts
index 072e46ba00..884e659d1a 100644
--- a/packages/trilium-core/src/routes/api/search.spec.ts
+++ b/packages/trilium-core/src/routes/api/search.spec.ts
@@ -30,12 +30,15 @@ describe("Search API (core)", () => {
});
it("returns structured quick-search results with snippets", async () => {
- const res = await api.get<{ searchResultNoteIds: string[]; searchResults: unknown[] }>(
+ const res = await api.get<{ searchResultNoteIds: string[]; searchResults: unknown[]; highlightedTokens: string[] }>(
`/api/quick-search/${UNIQUE_TOKEN}`
);
expect(res.status).toBe(200);
expect(res.body.searchResultNoteIds).toContain(createdNoteId);
expect(Array.isArray(res.body.searchResults)).toBe(true);
+ // highlightedTokens lets clients (quick-search dropdown, jump-to-match) know which
+ // tokens the server highlighted, without re-deriving them from the raw query string.
+ expect(res.body.highlightedTokens).toContain(UNIQUE_TOKEN.toLowerCase());
});
it("lists template note ids including a freshly-labelled template", async () => {
diff --git a/packages/trilium-core/src/routes/api/search.ts b/packages/trilium-core/src/routes/api/search.ts
index 302203a8cb..cf5be61a36 100644
--- a/packages/trilium-core/src/routes/api/search.ts
+++ b/packages/trilium-core/src/routes/api/search.ts
@@ -119,6 +119,7 @@ function quickSearch(req: Request<{ searchString: string }>) {
return {
searchResultNoteIds: searchResults.map((result) => result.noteId),
searchResults,
+ highlightedTokens: searchContext.highlightedTokens,
error: searchContext.getError()
};
}