Skip to content

Build your personal knowledge base with Trilium Notes

feat(search): blend the preview card with the note list

Elian Dorandbe74685e331
diff --git a/apps/client/src/widgets/collections/search/SearchResultCard.tsx b/apps/client/src/widgets/collections/search/SearchResultCard.tsx
index 3c128336b1..c9aeef4660 100644
--- a/apps/client/src/widgets/collections/search/SearchResultCard.tsx
+++ b/apps/client/src/widgets/collections/search/SearchResultCard.tsx
@@ -1,7 +1,12 @@
import type { HighlightedTokenInfo, SearchResultDetails } from "@triliumnext/commons";
+import clsx from "clsx";
+import { Fragment } from "preact";
+import { useEffect, useState } from "preact/hooks";
+import type FNote from "../../../entities/fnote";
import { t } from "../../../services/i18n";
import { calculateHash, type ViewScope } from "../../../services/link";
+import tree from "../../../services/tree";
import { AttributeSnippetBadges } from "../../react/Badge";
import { useNote, useNoteTitle } from "../../react/hooks";
import Icon from "../../react/Icon";
@@ -26,27 +31,43 @@ export default function SearchResultCard({ noteId, details, loading, highlighted
const liveTitle = useNoteTitle(noteId, undefined);
const title = liveTitle ?? details?.noteTitle ?? note?.title ?? "";
const icon = note?.getIcon() ?? details?.icon ?? "bx bx-note";
- const breadcrumb = getBreadcrumbTitle(details?.notePathTitle);
+ const fallbackBreadcrumb = useFallbackBreadcrumb(note, !details?.notePathTitle);
+ const breadcrumb = getBreadcrumbTitle(details?.notePathTitle) || fallbackBreadcrumb;
const viewScope: ViewScope = { searchTerms: searchTermsFor(details, highlightedTokens) };
const href = calculateHash({ notePath: noteId, viewScope });
+ const hasDetails = !!details || loading;
return (
- <a className="search-result-card" href={href}>
- <div className="search-result-card-header">
- <Icon className="search-result-card-icon" icon={icon} />
- <HighlightedText
- className="search-result-card-title"
- text={title}
- highlightedTokens={highlightedTokens}
- />
- {breadcrumb && <span className="search-result-card-path">{breadcrumb}</span>}
- </div>
- <SearchResultSnippet details={details} loading={loading} />
- <AttributeSnippetBadges
- snippet={details?.highlightedAttributeSnippet}
- className="search-result-card-badges"
- />
+ <a
+ className={clsx("tn-card-frame", "note-book-card", "search-result-card", "no-tooltip-preview",
+ note?.getColorClass(), note?.isArchived && "archived")}
+ href={href}
+ data-note-id={noteId}
+ >
+ <h5 className="note-book-header">
+ <Icon className="note-icon" icon={icon} />
+ <span className="note-book-title">
+ <span>
+ <HighlightedText
+ className="search-result-card-title"
+ text={title}
+ highlightedTokens={highlightedTokens}
+ />
+ {breadcrumb && <NotePath path={breadcrumb} />}
+ </span>
+ </span>
+ </h5>
+
+ {hasDetails && (
+ <div className="search-result-card-content">
+ <SearchResultSnippet details={details} loading={loading} />
+ <AttributeSnippetBadges
+ snippet={details?.highlightedAttributeSnippet}
+ className="search-result-card-badges"
+ />
+ </div>
+ )}
</a>
);
}
@@ -66,6 +87,61 @@ function SearchResultSnippet({ details, loading }: { details: SearchResultDetail
return <RawHtmlBlock className="search-result-card-snippet" html={details.highlightedContentSnippet ?? ""} />;
}
+/**
+ * The ancestor path, marked up like `tree.formatNotePath()` so the shared stylesheet hides the
+ * brackets and draws the separators as arrows, exactly as the note list's search results do.
+ */
+function NotePath({ path }: { path: string }) {
+ const segments = path.split(" › ");
+
+ return (
+ <small>
+ <span className="note-path">
+ <span className="path-bracket"> (</span>
+ {segments.map((segment, index) => (
+ <Fragment key={index}>
+ <span>{segment}</span>
+ {index < segments.length - 1 && <span className="path-delimiter"> / </span>}
+ </Fragment>
+ ))}
+ <span className="path-bracket">)</span>
+ </span>
+ </small>
+ );
+}
+
+/**
+ * The note's path from the tree, as the grid builds it, for the first render before the server's
+ * snippet details arrive. The details' path wins once they do, as it names the path the search
+ * found the note through.
+ */
+function useFallbackBreadcrumb(note: FNote | undefined, enabled: boolean) {
+ const [ breadcrumb, setBreadcrumb ] = useState<string>();
+
+ useEffect(() => {
+ if (!enabled) {
+ setBreadcrumb(undefined);
+ return;
+ }
+
+ const ancestorIds = note?.getBestNotePath()?.slice(1, -1) ?? [];
+ if (ancestorIds.length === 0) {
+ setBreadcrumb(undefined);
+ return;
+ }
+
+ let cancelled = false;
+ void tree.getNotePathTitle(ancestorIds.join("/")).then((title) => {
+ if (!cancelled) setBreadcrumb(title);
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [ note, enabled ]);
+
+ return breadcrumb;
+}
+
/** The breadcrumb shows the ancestor path only, i.e. the note-path title minus the note's own title. */
export function getBreadcrumbTitle(notePathTitle: string | undefined): string {
if (!notePathTitle) return "";
diff --git a/apps/client/src/widgets/collections/search/SearchResultsList.css b/apps/client/src/widgets/collections/search/SearchResultsList.css
index 2444b3285b..b2fbab8779 100644
--- a/apps/client/src/widgets/collections/search/SearchResultsList.css
+++ b/apps/client/src/widgets/collections/search/SearchResultsList.css
@@ -1,3 +1,5 @@
+@import "../legacy/ListOrGridView.css";
+
.search-results-list {
display: flex;
flex-direction: column;
@@ -40,59 +42,29 @@
min-width: 0;
}
- .search-result-card {
- display: block;
+ /* A grid card laid out one per row: the list keeps its frame and header, but has no expander. */
+ .search-result-card.note-book-card {
+ flex: 0 0 auto;
+ max-height: none;
+ width: 100%;
min-width: 0;
- padding: 10px 14px;
- border: 1px solid var(--main-border-color);
- border-radius: 8px;
- background: var(--accented-background-color);
color: inherit;
text-decoration: none;
- transition: background 0.15s ease, border-color 0.15s ease;
- }
-
- .search-result-card:hover {
- background: var(--hover-item-background-color);
- border-color: var(--main-border-color);
- text-decoration: none;
- }
-
- .search-result-card-header {
- display: flex;
- align-items: baseline;
- flex-wrap: wrap;
- gap: 4px 8px;
- min-width: 0;
- }
-
- .search-result-card-icon {
- flex: 0 0 auto;
- align-self: center;
+ user-select: text;
}
.search-result-card-title {
- flex: 1 1 auto;
- min-width: 0;
- font-weight: 600;
+ font-weight: 500;
overflow-wrap: anywhere;
}
- .search-result-card-path {
- flex: 0 1 auto;
- min-width: 0;
- margin-inline-start: auto;
- opacity: 0.6;
- font-size: 0.85em;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
+ .search-result-card-content {
+ padding: .5rem 1rem 1rem;
+ font-size: 0.85rem;
}
.search-result-card-snippet {
- margin-top: 4px;
line-height: 1.4;
- color: var(--muted-text-color);
overflow-wrap: anywhere;
}
@@ -107,7 +79,7 @@
background: linear-gradient(
90deg,
var(--main-border-color) 25%,
- var(--accented-background-color) 37%,
+ var(--card-background-color) 37%,
var(--main-border-color) 63%
);
background-size: 400% 100%;
diff --git a/apps/client/src/widgets/collections/search/SearchResultsList.spec.tsx b/apps/client/src/widgets/collections/search/SearchResultsList.spec.tsx
index 5ab31fea74..8dc5b33783 100644
--- a/apps/client/src/widgets/collections/search/SearchResultsList.spec.tsx
+++ b/apps/client/src/widgets/collections/search/SearchResultsList.spec.tsx
@@ -87,8 +87,12 @@ describe("SearchResultCard", () => {
// type widget can highlight/jump to them via ViewScope.searchTerms.
expect(link?.getAttribute("href")).toBe(`#${note.noteId}?searchTerms=sync`);
expect(container.querySelector(".search-result-card-title")?.textContent).toBe("Meeting notes");
- // Breadcrumb is the note-path title minus the note's own (last) segment.
- expect(container.querySelector(".search-result-card-path")?.textContent).toBe("Work › 2026");
+ // Breadcrumb is the note-path title minus the note's own (last) segment, marked up as the
+ // note list does, so the shared stylesheet hides its brackets and draws the separators.
+ const path = container.querySelector(".search-result-card .note-path");
+ expect(path?.textContent).toContain("Work / 2026");
+ expect(path?.querySelectorAll(".path-bracket")).toHaveLength(2);
+ expect(path?.querySelector(".path-delimiter")?.textContent).toBe(" / ");
const snippet = container.querySelector(".search-result-card-snippet");
expect(snippet?.innerHTML).toContain("<b>sync</b>");
diff --git a/apps/client/src/widgets/collections/search/SearchResultsList.tsx b/apps/client/src/widgets/collections/search/SearchResultsList.tsx
index 27dcefb3e8..336b091e83 100644
--- a/apps/client/src/widgets/collections/search/SearchResultsList.tsx
+++ b/apps/client/src/widgets/collections/search/SearchResultsList.tsx
@@ -1,6 +1,7 @@
import "./SearchResultsList.css";
import type { HighlightedTokenInfo } from "@triliumnext/commons";
+import clsx from "clsx";
import { useMemo } from "preact/hooks";
import type FNote from "../../../entities/fnote";
@@ -45,7 +46,7 @@ export default function SearchResultsList({ note, noteIds, ntxId, highlightedTok
});
return (
- <div className="search-results-list">
+ <div className="search-results-list note-list">
<CollectionProperties
note={note}
centerChildren={<Pager className="search-results-list-top-pager" {...pagination} />}
@@ -58,7 +59,7 @@ export default function SearchResultsList({ note, noteIds, ntxId, highlightedTok
}
/>
- <div className="search-results-list-cards">
+ <div className="search-results-list-cards note-list-container search-results">
{pageNoteIds.map((noteId) => (
<SearchResultCard
key={noteId}