Skip to content

Build your personal knowledge base with Trilium Notes

client/options/search: always show the preview for syntax highlight themes

Adorian Doraneaab75b8ec78
diff --git a/apps/client/src/widgets/type_widgets/options/code_notes.tsx b/apps/client/src/widgets/type_widgets/options/code_notes.tsx
index e729ae7c28..c852386ed0 100644
--- a/apps/client/src/widgets/type_widgets/options/code_notes.tsx
+++ b/apps/client/src/widgets/type_widgets/options/code_notes.tsx
@@ -149,7 +149,7 @@ function Appearance({ wordWrapping, indentSize }: AppearanceProps) {
{/* A specimen of the editor rather than a control standing beside a label, shown
the way a code block is shown in a note. */}
- <CardSection className="code-note-preview">
+ <CardSection className="code-note-preview" filterRole="companion">
<CodeNotePreview wordWrapping={wordWrapping} themeName={effectiveTheme} indentSize={indentSize} />
</CardSection>
</Card>
diff --git a/apps/client/src/widgets/type_widgets/options/search_page.css b/apps/client/src/widgets/type_widgets/options/search_page.css
index 9093c7f3ac..0ac2e3c6cc 100644
--- a/apps/client/src/widgets/type_widgets/options/search_page.css
+++ b/apps/client/src/widgets/type_widgets/options/search_page.css
@@ -38,18 +38,18 @@ body.mobile .options-search .options-page-header {
}
/*
- * A page brings its whole self along, of which the search wants only the cards: its header names
+ * A page brings its whole self along, of which the search wants only what matched: its header names
* the page it thinks it is showing, and its tables and listings are not settings anyone can search
* for. A page is free to keep its cards inside a block of its own (the shortcuts page does), so
- * what is kept is anything with a card still left in it rather than the cards alone.
+ * what is kept is any block with something left in it rather than the cards alone.
*
- * Something is left when a card matched by name, or when a single setting inside one did — the
- * same test decides whether a block is worth keeping, whether a page is worth naming, and whether
- * the search came back with anything at all. A setting kept only for the details under it does not
- * count, since it is shown for their sake and goes with them (see `Card.css`).
+ * The page itself is a filter scope, and goes when empty by the rule in filter.css.
*/
-.options-search-page > :not(.tn-card, .options-search-page-title):not(:has(.tn-card:not(.tn-card-filter-unmatched), .tn-card-option:not(.tn-card-option-filter-unmatched))),
-.options-search-page:not(:has(.tn-card:not(.tn-card-filter-unmatched), .tn-card-option:not(.tn-card-option-filter-unmatched))),
-.options-search-results:has(.tn-card:not(.tn-card-filter-unmatched), .tn-card-option:not(.tn-card-option-filter-unmatched)) .options-search-empty {
+.options-search-page > :not(.options-search-page-title, .tn-filter-match):not(:has(.tn-filter-match)) {
+ display: none;
+}
+
+/* Nothing to stand in for once the search has something to show. */
+.options-search-results:has(.tn-filter-match) .options-search-empty {
display: none;
}
diff --git a/apps/client/src/widgets/type_widgets/options/search_page.tsx b/apps/client/src/widgets/type_widgets/options/search_page.tsx
index 815bb1ad13..8f603458f4 100644
--- a/apps/client/src/widgets/type_widgets/options/search_page.tsx
+++ b/apps/client/src/widgets/type_widgets/options/search_page.tsx
@@ -1,12 +1,13 @@
import "./search_page.css";
+import clsx from "clsx";
import type { ComponentChildren } from "preact";
import { useEffect, useState } from "preact/hooks";
import type FNote from "../../../entities/fnote";
import { t } from "../../../services/i18n";
import { useOptionPages } from "../../dialogs/OptionsDialog";
-import { FilterProvider } from "../../react/filter";
+import { FilterProvider, filterRoleClass, useIsFiltering } from "../../react/filter";
import { useDebouncedValue, useNoteContext } from "../../react/hooks";
import LoadingSpinner from "../../react/LoadingSpinner";
import NoItems from "../../react/NoItems";
@@ -100,10 +101,12 @@ function SearchedPages() {
/** One page's cards, under the name of the page they belong to, so a result says where it lives. */
function SearchedPage({ page, ...pageProps }: { page: FNote } & Omit<TypeWidgetProps, "note">) {
const Page = CONTENT_WIDGETS[page.noteId];
+ const filtering = useIsFiltering();
if (!Page) return null;
+ // A page with nothing left in it is not worth naming, which the filter's own rule sees to.
return (
- <section className="options-search-page">
+ <section className={clsx("options-search-page", filterRoleClass(filtering && "scope"))}>
<h3 className="options-search-page-title">
<span className={page.getIcon()} aria-hidden="true" />
{page.title}
diff --git a/apps/client/src/widgets/type_widgets/options/text_notes.tsx b/apps/client/src/widgets/type_widgets/options/text_notes.tsx
index dba25b25bf..ff09a7e9d0 100644
--- a/apps/client/src/widgets/type_widgets/options/text_notes.tsx
+++ b/apps/client/src/widgets/type_widgets/options/text_notes.tsx
@@ -596,7 +596,7 @@ function CodeBlockStyle() {
/>
</OptionCardSection>
- <CardSection className="code-block-preview">
+ <CardSection className="code-block-preview" filterRole="companion">
<CodeBlockPreview theme={effectiveTheme} wordWrap={codeBlockWordWrap} tabWidth={codeBlockTabWidth} />
</CardSection>
</Card>