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(quick-search): show a result's matching attributes as badges
Elian Doran5f5636541414
diff --git a/apps/client/src/widgets/quick_search.css b/apps/client/src/widgets/quick_search.cssindex b63c41f595..8c72cee4ca 100644--- a/apps/client/src/widgets/quick_search.css+++ b/apps/client/src/widgets/quick_search.css@@ -208,9 +208,15 @@}.search-result-attributes {- opacity: .5;+ display: flex;+ flex-wrap: wrap;+ gap: 4px;+ margin-top: 4px;padding: 0 8px;- font-size: .75em;++ .ext-badge {+ --color: var(--muted-text-color);+ }}.search-result-content {diff --git a/apps/client/src/widgets/quick_search.spec.tsx b/apps/client/src/widgets/quick_search.spec.tsxindex 3b24457256..254f5abc66 100644--- a/apps/client/src/widgets/quick_search.spec.tsx+++ b/apps/client/src/widgets/quick_search.spec.tsx@@ -74,7 +74,8 @@ describe("QuickSearch", () => {expect(first.classList.contains("no-tooltip-preview")).toBe(true);expect(first.querySelector(".quick-search-item-icon")?.classList.contains("bx-note")).toBe(true);expect(first.querySelector(".search-result-title")?.innerHTML).toBe("<b>Note</b> 0");- expect(first.querySelector(".search-result-attributes")?.innerHTML).toBe("#year=1954 #author=tolkien");+ const badges = first.querySelectorAll(".search-result-attributes > .ext-badge.outline");+ expect([ ...badges ].map((badge) => badge.textContent)).toEqual([ "#year=1954", "#author=tolkien" ]);expect(first.querySelector(".search-result-content")?.innerHTML).toBe("about <b>hello</b>");});diff --git a/apps/client/src/widgets/quick_search.tsx b/apps/client/src/widgets/quick_search.tsxindex 6d43820e43..c794df8ca8 100644--- a/apps/client/src/widgets/quick_search.tsx+++ b/apps/client/src/widgets/quick_search.tsx@@ -14,6 +14,7 @@ import type { ShortcutHintDefinition } from "../services/shortcut_hints";import { isMobile } from "../services/utils";import ActionButton from "./react/ActionButton";import { ExtendedAdmonition } from "./react/Admonition";+import { AttributeSnippetBadges } from "./react/Badge";import Button from "./react/Button";import { focusListItem } from "./react/FormList";import { useTriliumEvent } from "./react/hooks";@@ -347,13 +348,10 @@ function QuickSearchResult({ result, viewScope, onOpen }: {/></div>- {result.highlightedAttributeSnippet && (- // The attributes share one line, so the line breaks between them become spaces.- <RawHtmlBlock- className="search-result-attributes"- html={result.highlightedAttributeSnippet.replace(/<br\s?\/?>/g, " ")}- />- )}+ <AttributeSnippetBadges+ snippet={result.highlightedAttributeSnippet}+ className="search-result-attributes"+ />{result.highlightedContentSnippet && (<RawHtmlBlock