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
client/options/text notes: switch to the new card component
Adorian Doran27165f847249
diff --git a/apps/client/src/widgets/type_widgets/options/components/RadioWithIllustration.css b/apps/client/src/widgets/type_widgets/options/components/RadioWithIllustration.cssindex 2d5bd2c34e..d774315c66 100644--- a/apps/client/src/widgets/type_widgets/options/components/RadioWithIllustration.css+++ b/apps/client/src/widgets/type_widgets/options/components/RadioWithIllustration.css@@ -4,7 +4,7 @@padding: 0;display: flex;gap: 1.5em;- justify-content: center;+ justify-content: start;figure {figcaption {diff --git a/apps/client/src/widgets/type_widgets/options/custom_replacements.spec.tsx b/apps/client/src/widgets/type_widgets/options/custom_replacements.spec.tsxindex f02076246c..5e32f62176 100644--- a/apps/client/src/widgets/type_widgets/options/custom_replacements.spec.tsx+++ b/apps/client/src/widgets/type_widgets/options/custom_replacements.spec.tsx@@ -9,7 +9,7 @@ const state = vi.hoisted(() => ({watchers: new Set<(newValue: string) => void>()}));-// Only `useTriliumOption` is replaced — the rest of the module stays real, so the chips and boxes+// Only `useTriliumOption` is replaced — the rest of the module stays real, so the segments and boxes// this renders keep the hooks they use.//// The stand-in holds the value in state and re-reads it when the store changes, as the real hook does@@ -55,9 +55,9 @@ function renderEditor() {return container;}-/** The replacements as the chips show them, each read as the `from → to` it stands for. */-const chips = (container: HTMLElement) =>- [ ...container.querySelectorAll(".tn-chip > span") ].map((chip) => chip.textContent);+/** The replacements as the segments show them, each read as the `from → to` it stands for. */+const pairs = (container: HTMLElement) =>+ [ ...container.querySelectorAll(".custom-replacement-pair") ].map((pair) => pair.textContent);/** The two boxes the next pair is typed into. */const draftBoxes = (container: HTMLElement) => [ ...container.querySelectorAll("input") ];@@ -95,11 +95,11 @@ afterEach(() => {});describe("CustomReplacements", () => {- it("shows what is held as chips, and offers empty boxes for the next", () => {+ it("shows what is held as segments, and offers empty boxes for the next", () => {state.stored = `[{"from":"TN","to":"Trilium Notes"},{"from":"teh","to":"the"}]`;const container = renderEditor();- expect(chips(container)).toEqual([ "TN → Trilium Notes", "teh → the" ]);+ expect(pairs(container)).toEqual([ "TN → Trilium Notes", "teh → the" ]);expect(draftBoxes(container).map((box) => box.value)).toEqual([ "", "" ]);});@@ -109,7 +109,7 @@ describe("CustomReplacements", () => {addPair(container, "TN", "Trilium Notes");expect(stored()).toEqual([ { from: "TN", to: "Trilium Notes" } ]);- expect(chips(container)).toEqual([ "TN → Trilium Notes" ]);+ expect(pairs(container)).toEqual([ "TN → Trilium Notes" ]);expect(draftBoxes(container).map((box) => box.value)).toEqual([ "", "" ]);});@@ -122,7 +122,7 @@ describe("CustomReplacements", () => {// Storing it would put an entry in the set that could never fire.expect(state.writes).toEqual([]);- expect(chips(container)).toEqual([]);+ expect(pairs(container)).toEqual([]);});it("replaces an entry typed a second time rather than holding both", () => {@@ -145,15 +145,15 @@ describe("CustomReplacements", () => {expect(stored()).toEqual([ { from: "tn", to: "Trilium" } ]);});- it("removes the chip that was pressed, keeping its neighbours", () => {+ it("removes the pair that was pressed, keeping its neighbours", () => {state.stored = `[{"from":"TN","to":"Trilium Notes"},{"from":"teh","to":"the"}]`;const container = renderEditor();- const [ , removeSecond ] = [ ...container.querySelectorAll<HTMLButtonElement>(".tn-chip-remove") ];+ const [ , removeSecond ] = [ ...container.querySelectorAll<HTMLButtonElement>(".custom-replacement-remove") ];act(() => removeSecond.click());expect(stored()).toEqual([ { from: "TN", to: "Trilium Notes" } ]);- expect(chips(container)).toEqual([ "TN → Trilium Notes" ]);+ expect(pairs(container)).toEqual([ "TN → Trilium Notes" ]);});it("shows a list that arrived from elsewhere without being asked twice", () => {@@ -164,7 +164,7 @@ describe("CustomReplacements", () => {act(() => writeStore(`[{"from":"CT","to":"CherryTree"}]`));- expect(chips(container)).toEqual([ "CT → CherryTree" ]);+ expect(pairs(container)).toEqual([ "CT → CherryTree" ]);});it("leaves a pair being typed alone when a list arrives", () => {@@ -176,7 +176,7 @@ describe("CustomReplacements", () => {act(() => writeStore(`[{"from":"CT","to":"CherryTree"}]`));- expect(chips(container)).toEqual([ "CT → CherryTree" ]);+ expect(pairs(container)).toEqual([ "CT → CherryTree" ]);expect(draftBoxes(container).map((box) => box.value)).toEqual([ "TN", "Trilium No" ]);// ...and taking it keeps what arrived rather than replacing it.diff --git a/apps/client/src/widgets/type_widgets/options/text_notes.css b/apps/client/src/widgets/type_widgets/options/text_notes.cssindex 721f16a70f..b44eb9077e 100644--- a/apps/client/src/widgets/type_widgets/options/text_notes.css+++ b/apps/client/src/widgets/type_widgets/options/text_notes.css@@ -124,107 +124,95 @@}}-.code-sample-wrapper {- padding-top: 0.75em;+/* The illustrated choice reads as a pair of drawings rather than a filled-in control, so the card+ gives it room and stands back behind it — the same treatment the layout choices have. */+.text-notes-toolbar-style .tn-card {+ --card-padding-block: 12px;+ --card-background-color: transparent;}-.custom-replacements {- display: flex;- flex-direction: column;- gap: 8px;- padding-top: 0.75em;-- /*- * The two boxes, the arrow between them and the button asking for what they hold, kept together- * as the one thing they are: a pair is entered, not a value, so they move and wrap as a unit- * rather than the `to` box stranding itself under the chips.- *- * Given the whole line at the foot of the field rather than a place in among the chips. A pair- * needs two boxes and reads as a row of its own, where a single value's box can sit at the end- * of the set it adds to; and where the next one is entered stays put as chips are taken and- * dropped, instead of moving with the end of a set that wraps.- */- .custom-replacement-entry {- display: flex;- align-items: center;- gap: 6px;- flex: 0 0 100%;- min-width: 0;- }+/* Bootstrap gives a select the whole width of what holds it, which in a card row leaves the label+ beside it a word to the line. Sized to what it offers instead, and cut short rather than carried+ across the row — the bounds the option rows carried before these were card segments. */+.text-notes-replacements select,+.text-notes-code-blocks select {+ width: auto;+ min-width: 150px;+ max-width: 260px;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+}- /*- * Told apart from the set above it, once there is one: what is held and what is being added are- * two different things, and the field would otherwise read as a single run of controls. Nothing- * to divide it from while the set is empty, where the bar is the whole of the field.- */- .custom-replacement-entry:not(:first-child) {- margin-top: 4px;- padding-top: 8px;- border-top: 1px solid var(--main-border-color);- }+/* The same for a text box, which is a format string of known length rather than a sentence: `auto`+ is the browser's own twenty characters, which is what the format written in it needs. */+.text-notes-editor input[type="text"] {+ width: auto;+ max-width: 100%;+}- /*- * The boxes keep an edge of their own, which the chips above them give up. `.tn-field` strips it- * from the boxes it holds directly so they read as lying on the field rather than sitting in it —- * but that is for a box standing among chips, which would otherwise read as another one. This bar- * is a row apart below them and is the only place a pair can be entered, so it says where to type- * the way `values_input` does for the same reason: with neither edge nor ground, a box reads as a- * gap rather than as somewhere to write. Said here rather than left to Bootstrap, whose border- * this happens to inherit only because the child selector above does not reach a nested box.- */- .custom-replacement-entry > .form-control {- flex: 1 1 0;- min-width: 6ch;- background-color: var(--input-background-color);- border: 1px solid var(--main-border-color);- border-radius: var(--badge-radius, 12px);- padding: 4px 10px;+/* A figure and the unit it is read in, sized to the figure: Bootstrap gives an input group the whole+ width of what holds it, which in a card row is the row. */+.text-notes-number .tn-number-unit-pair {+ width: auto;- /* The same ring the field wears, so a box showing its own focus looks no different from the- field having shown it. Bootstrap's shadow is cleared rather than left under it, two focus- treatments on one box being what this whole rule set is avoiding. */- &:focus {- outline: 2px solid var(--input-focus-outline-color);- box-shadow: none;- }+ input[type="number"] {+ width: 7em;}+}- /* Roomier than a chip field packed for a note's side pane: this one sits on a settings page with- width to spare, and holds a set to read as well as a bar to type in. */- > .tn-field {- gap: 6px;- padding: 6px 8px;+/* Each pair held, and the boxes the next one is typed into: one segment apiece, what is written on+ the leading edge and the way to be rid of it on the trailing one. */+.custom-replacement {+ display: flex;+ align-items: center;+ gap: 8px;+}- /*- * The field rings itself when something inside takes the focus, standing in for boxes that- * have given up frames of their own. These have kept theirs and ring themselves, so the- * field doing it too draws a second ring around the first. Only for the boxes: a chip's- * remove button has nothing of its own to show focus with, and still needs the field for it.- */- &:focus-within:has(> .custom-replacement-entry > .form-control:focus) {- outline: none;- }- }+.custom-replacement-pair {+ flex: 1 1 auto;+ min-width: 0;+ overflow-wrap: anywhere;+}- .custom-replacement-arrow {- flex-shrink: 0;- opacity: 0.5;+/*+ * The two boxes, the arrow between them and the button asking for what they hold, kept together as+ * the one thing they are: a pair is entered, not a value, so they take the segment between them+ * rather than the `to` box stranding itself on a line of its own.+ */+.custom-replacement-entry {+ display: flex;+ align-items: center;+ gap: 6px;+ width: 100%;+ min-width: 0;++ > .form-control {+ flex: 1 1 0;+ min-width: 6ch;+ padding: 4px 10px;}+}- /*- * Sized to the button a chip is removed by rather than to an icon button anywhere else, so the- * field does not grow the moment a pair is complete and shrink again once it is taken — a field- * is as tall as the tallest thing in it.- */- .custom-replacement-add {- --icon-button-size: 20px;- --icon-button-icon-ratio: 0.9;+.custom-replacement-arrow {+ flex-shrink: 0;+ opacity: 0.5;+}- flex-shrink: 0;- width: 20px;- height: 20px;- padding: 0;- font-size: 18px;- line-height: 1;- }+/*+ * Both sized to the segment rather than to an icon button anywhere else, so a segment does not grow+ * the moment a pair is complete and shrink again once it is taken — a row is as tall as the tallest+ * thing in it.+ */+.custom-replacement-add,+.custom-replacement-remove {+ --icon-button-size: 20px;+ --icon-button-icon-ratio: 0.9;++ flex-shrink: 0;+ width: 20px;+ height: 20px;+ padding: 0;+ font-size: 18px;+ line-height: 1;}diff --git a/apps/client/src/widgets/type_widgets/options/text_notes.tsx b/apps/client/src/widgets/type_widgets/options/text_notes.tsxindex 9c9fda6457..ad4499a282 100644--- a/apps/client/src/widgets/type_widgets/options/text_notes.tsx+++ b/apps/client/src/widgets/type_widgets/options/text_notes.tsx@@ -10,23 +10,22 @@ import { t } from "../../../services/i18n";import { ensureMimeTypesForHighlighting, loadHighlightingTheme } from "../../../services/syntax_highlight";import { formatDateTime, toggleBodyClass } from "../../../services/utils";import ActionButton from "../../react/ActionButton";-import Chip from "../../react/Chip";+import { Card, CardOption, CardSection } from "../../react/Card";import Dropdown from "../../react/Dropdown";import FormGroup from "../../react/FormGroup";import { FormListItem } from "../../react/FormList";import FormSelect, { FormSelectGroup, FormSelectWithGroups } from "../../react/FormSelect";import FormText from "../../react/FormText";import FormTextBox, { FormTextBoxWithUnit } from "../../react/FormTextBox";+import FormToggle from "../../react/FormToggle";import { useColorScheme, useTriliumOption, useTriliumOptionBool } from "../../react/hooks";import { getHtml } from "../../react/RawHtml";+import SegmentedChoice, { SegmentedChoiceOption } from "../../react/SegmentedChoice";import { QUOTE_MARK_PRESETS } from "../text/quotes";import { type CustomReplacement, parseCustomReplacements } from "../text/replacements";import OptionsPageHeader from "./components/OptionsPageHeader";-import OptionsRow, { OptionsRowWithToggle } from "./components/OptionsRow";-import OptionsSection from "./components/OptionsSection";import RadioWithIllustration from "./components/RadioWithIllustration";import RelatedSettings from "./components/RelatedSettings";-import ThemeModeSelector from "./components/ThemeModeSelector";import { HighlightsListOptions } from "./highlights_list_options";const isNewLayout = isExperimentalFeatureEnabled("new-layout");@@ -35,6 +34,7 @@ export default function TextNoteSettings() {return (<><OptionsPageHeader />+ <ToolbarStyle /><FormattingToolbar /><EditorFeatures /><AutomaticReplacements />@@ -53,38 +53,59 @@ export default function TextNoteSettings() {}function FormattingToolbar() {- const [ textNoteEditorType, setTextNoteEditorType ] = useTriliumOption("textNoteEditorType");+ const [ textNoteEditorType ] = useTriliumOption("textNoteEditorType");const [ textNoteEditorMultilineToolbar, setTextNoteEditorMultilineToolbar ] = useTriliumOptionBool("textNoteEditorMultilineToolbar");return (- <OptionsSection title={t("editing.editor_type.label")}>- <OptionsRow name="editor-type" label={t("editing.editor_type.toolbar_style")}>- <RadioWithIllustration- currentValue={textNoteEditorType}- onChange={setTextNoteEditorType}- values={[- {- key: "ckeditor-balloon",- text: t("editing.editor_type.floating.title"),- illustration: <ToolbarIllustration type="floating" />- },- {- key: "ckeditor-classic",- text: t("editing.editor_type.fixed.title"),- illustration: <ToolbarIllustration type="fixed" />- }- ]}- />- </OptionsRow>-- <OptionsRowWithToggle- name="multiline-toolbar"- label={t("editing.editor_type.multiline-toolbar")}- currentValue={textNoteEditorMultilineToolbar}- onChange={setTextNoteEditorMultilineToolbar}- disabled={textNoteEditorType === "ckeditor-balloon"}- />- </OptionsSection>+ <div className="options-section">+ <Card heading={t("editing.editor_type.label")}>+ <CardOption+ name="multiline-toolbar"+ label={t("editing.editor_type.multiline-toolbar")}+ >+ <FormToggle+ currentValue={textNoteEditorMultilineToolbar}+ onChange={setTextNoteEditorMultilineToolbar}+ // Nothing to wrap onto a second line where the toolbar follows the cursor.+ disabled={textNoteEditorType === "ckeditor-balloon"}+ />+ </CardOption>+ </Card>+ </div>+ );+}++/**+ * Where the editing tools are kept, shown as a picture of each rather than named in words. Given a+ * card of its own for the same reason the layout choices have one: an illustrated choice is too large+ * to stand as a value beside a label, so what it is called becomes the card's heading.+ */+function ToolbarStyle() {+ const [ textNoteEditorType, setTextNoteEditorType ] = useTriliumOption("textNoteEditorType");++ return (+ <div className="options-section text-notes-toolbar-style">+ <Card heading={t("editing.editor_type.toolbar_style")}>+ <CardSection>+ <RadioWithIllustration+ currentValue={textNoteEditorType}+ onChange={setTextNoteEditorType}+ values={[+ {+ key: "ckeditor-balloon",+ text: t("editing.editor_type.floating.title"),+ illustration: <ToolbarIllustration type="floating" />+ },+ {+ key: "ckeditor-classic",+ text: t("editing.editor_type.fixed.title"),+ illustration: <ToolbarIllustration type="fixed" />+ }+ ]}+ />+ </CardSection>+ </Card>+ </div>);}@@ -139,55 +160,57 @@ function EditorFeatures() {const [htmlSupportEnabled, setHtmlSupportEnabled] = useTriliumOptionBool("textNoteHtmlSupportEnabled");return (- <OptionsSection title={t("editorfeatures.title")}>- <OptionsRowWithToggle- name="emoji-completion-enabled"- label={t("editorfeatures.emoji_completion_enabled")}- description={t("editorfeatures.emoji_completion_description")}- currentValue={emojiCompletionEnabled}- onChange={setEmojiCompletionEnabled}- />+ <div className="options-section">+ <Card heading={t("editorfeatures.title")}>+ <CardOption+ name="emoji-completion-enabled"+ label={t("editorfeatures.emoji_completion_enabled")}+ description={t("editorfeatures.emoji_completion_description")}+ >+ <FormToggle currentValue={emojiCompletionEnabled} onChange={setEmojiCompletionEnabled} />+ </CardOption>- <OptionsRowWithToggle- name="auto-link-previews-enabled"- label={t("editorfeatures.auto_link_previews_enabled")}- description={t("editorfeatures.auto_link_previews_description")}- currentValue={autoLinkPreviewsEnabled}- onChange={setAutoLinkPreviewsEnabled}- />+ <CardOption+ name="auto-link-previews-enabled"+ label={t("editorfeatures.auto_link_previews_enabled")}+ description={t("editorfeatures.auto_link_previews_description")}+ >+ <FormToggle currentValue={autoLinkPreviewsEnabled} onChange={setAutoLinkPreviewsEnabled} />+ </CardOption>- <OptionsRowWithToggle- name="note-completion-enabled"- label={t("editorfeatures.note_completion_enabled")}- description={t("editorfeatures.note_completion_description")}- currentValue={noteCompletionEnabled}- onChange={setNoteCompletionEnabled}- />+ <CardOption+ name="note-completion-enabled"+ label={t("editorfeatures.note_completion_enabled")}+ description={t("editorfeatures.note_completion_description")}+ >+ <FormToggle currentValue={noteCompletionEnabled} onChange={setNoteCompletionEnabled} />+ </CardOption>- <OptionsRowWithToggle- name="slash-commands-enabled"- label={t("editorfeatures.slash_commands_enabled")}- description={t("editorfeatures.slash_commands_description")}- currentValue={slashCommandsEnabled}- onChange={setSlashCommandsEnabled}- />+ <CardOption+ name="slash-commands-enabled"+ label={t("editorfeatures.slash_commands_enabled")}+ description={t("editorfeatures.slash_commands_description")}+ >+ <FormToggle currentValue={slashCommandsEnabled} onChange={setSlashCommandsEnabled} />+ </CardOption>- <OptionsRowWithToggle- name="content-hints-enabled"- label={t("editorfeatures.content_hints_enabled")}- description={t("editorfeatures.content_hints_description")}- currentValue={contentHintsEnabled}- onChange={setContentHintsEnabled}- />+ <CardOption+ name="content-hints-enabled"+ label={t("editorfeatures.content_hints_enabled")}+ description={t("editorfeatures.content_hints_description")}+ >+ <FormToggle currentValue={contentHintsEnabled} onChange={setContentHintsEnabled} />+ </CardOption>- <OptionsRowWithToggle- name="html-support-enabled"- label={t("editorfeatures.html_support_enabled")}- description={t("editorfeatures.html_support_description")}- currentValue={htmlSupportEnabled}- onChange={setHtmlSupportEnabled}- />- </OptionsSection>+ <CardOption+ name="html-support-enabled"+ label={t("editorfeatures.html_support_enabled")}+ description={t("editorfeatures.html_support_description")}+ >+ <FormToggle currentValue={htmlSupportEnabled} onChange={setHtmlSupportEnabled} />+ </CardOption>+ </Card>+ </div>);}@@ -204,49 +227,54 @@ function AutomaticReplacements() {const [symbolsEnabled, setSymbolsEnabled] = useTriliumOptionBool("textNoteSymbolReplacementsEnabled");return (- <OptionsSection title={t("automatic_replacements.title")} description={t("automatic_replacements.description")}>- <OptionsRow- name="double-quote-style"- label={t("automatic_replacements.double_quotes")}- description={t("automatic_replacements.double_quotes_description")}+ <div className="options-section text-notes-replacements">+ <Card+ heading={t("automatic_replacements.title")}+ description={t("automatic_replacements.description")}>- <QuoteStyleSelect currentValue={doubleQuoteStyle} onChange={setDoubleQuoteStyle} />- </OptionsRow>+ <CardOption+ name="double-quote-style"+ label={t("automatic_replacements.double_quotes")}+ description={t("automatic_replacements.double_quotes_description")}+ >+ <QuoteStyleSelect currentValue={doubleQuoteStyle} onChange={setDoubleQuoteStyle} />+ </CardOption>- <OptionsRow- name="single-quote-style"- label={t("automatic_replacements.single_quotes")}- description={t("automatic_replacements.single_quotes_description")}- >- <QuoteStyleSelect currentValue={singleQuoteStyle} onChange={setSingleQuoteStyle} />- </OptionsRow>-- <OptionsRowWithToggle- name="punctuation-replacements-enabled"- label={t("automatic_replacements.punctuation")}- description={t("automatic_replacements.punctuation_description")}- currentValue={punctuationEnabled}- onChange={setPunctuationEnabled}- />+ <CardOption+ name="single-quote-style"+ label={t("automatic_replacements.single_quotes")}+ description={t("automatic_replacements.single_quotes_description")}+ >+ <QuoteStyleSelect currentValue={singleQuoteStyle} onChange={setSingleQuoteStyle} />+ </CardOption>- <OptionsRowWithToggle- name="math-replacements-enabled"- label={t("automatic_replacements.math")}- description={t("automatic_replacements.math_description")}- currentValue={mathEnabled}- onChange={setMathEnabled}- />+ <CardOption+ name="punctuation-replacements-enabled"+ label={t("automatic_replacements.punctuation")}+ description={t("automatic_replacements.punctuation_description")}+ >+ <FormToggle currentValue={punctuationEnabled} onChange={setPunctuationEnabled} />+ </CardOption>- <OptionsRowWithToggle- name="symbol-replacements-enabled"- label={t("automatic_replacements.symbols")}- description={t("automatic_replacements.symbols_description")}- currentValue={symbolsEnabled}- onChange={setSymbolsEnabled}- />+ <CardOption+ name="math-replacements-enabled"+ label={t("automatic_replacements.math")}+ description={t("automatic_replacements.math_description")}+ >+ <FormToggle currentValue={mathEnabled} onChange={setMathEnabled} />+ </CardOption>- <CustomReplacements />- </OptionsSection>+ <CardOption+ name="symbol-replacements-enabled"+ label={t("automatic_replacements.symbols")}+ description={t("automatic_replacements.symbols_description")}+ >+ <FormToggle currentValue={symbolsEnabled} onChange={setSymbolsEnabled} />+ </CardOption>++ <CustomReplacements />+ </Card>+ </div>);}@@ -276,8 +304,8 @@ function QuoteStyleSelect({ currentValue, onChange }: { currentValue: string, on}/**- * The user's own replacements: those already held as chips, and a pair of boxes after them for the- * next one.+ * The user's own replacements: one nested segment per pair already held, and a last segment holding+ * the boxes the next one is typed into.** Nothing is copied into local state but the pair being typed. What is held *is* the option, read* back on every render, so a list arriving from another device or a second settings tab is simply@@ -285,10 +313,10 @@ function QuoteStyleSelect({ currentValue, onChange }: { currentValue: string, on* it. The rows this replaced needed a guard for each of those; a set that is added to and removed* from rather than edited in place has neither problem to guard against.*- * A pair cannot be edited once taken, which is what a chip costs. Typing a `from` already held- * replaces that entry instead of adding a second one, which gives the editing back without an- * affordance for it — and a second entry under the same `from` would in any case be dead weight,- * since the first match is the one that fires.+ * A pair cannot be edited once taken. Typing a `from` already held replaces that entry instead of+ * adding a second one, which gives the editing back without an affordance for it — and a second+ * entry under the same `from` would in any case be dead weight, since the first match is the one+ * that fires.*/export function CustomReplacements() {const [ storedJson, setStoredJson ] = useTriliumOption("textNoteCustomReplacements");@@ -321,64 +349,68 @@ export function CustomReplacements() {}return (- <div className="custom-replacements">- <div className="option-row-label">- <label>{t("automatic_replacements.custom")}</label>- <small className="option-row-description">{t("automatic_replacements.custom_description")}</small>- </div>-- <div className="tn-field">- {replacements.map((replacement) => (- <Chip- key={replacement.from}- removeButtonText={t("automatic_replacements.custom_remove")}- onRemove={() => save(replacements.filter((held) => held.from !== replacement.from))}- >- <span>{replacement.from} → {replacement.to}</span>- </Chip>- ))}-- {/* The two boxes and the button asking for what they hold are one thing on the page,- so they wrap as one rather than the button stranding itself on a line of its own. */}- <div- className="custom-replacement-entry"- ref={entryRef}- onFocusOut={(e) => {- // Moving between the two boxes is not leaving the pair. Only a complete one- // is taken on the way out: half of a replacement is not a replacement, and- // storing it would put an entry in the set that could never fire.- if (e.relatedTarget instanceof Node && entryRef.current?.contains(e.relatedTarget)) return;- if (isComplete) take();- }}- >- <FormTextBox- inputRef={fromRef}- currentValue={draftFrom}- placeholder={t("automatic_replacements.custom_from_placeholder")}- onChange={setDraftFrom}- onKeyDown={(e) => e.key === "Enter" && take()}- />- <span className="custom-replacement-arrow" aria-hidden="true">→</span>- <FormTextBox- currentValue={draftTo}- placeholder={t("automatic_replacements.custom_to_placeholder")}- onChange={setDraftTo}- onKeyDown={(e) => e.key === "Enter" && take()}- />-- {/* Enter takes the pair, but nothing on the page says so — so once there is a- whole one to take, the same offer appears where it can be seen. */}- {isComplete && (+ <CardOption+ className="custom-replacements"+ label={t("automatic_replacements.custom")}+ description={t("automatic_replacements.custom_description")}+ subSectionsVisible+ subSections={[+ ...replacements.map((replacement) => (+ <CardSection key={replacement.from} className="custom-replacement">+ <span className="custom-replacement-pair">{replacement.from} → {replacement.to}</span><ActionButton- className="custom-replacement-add"- icon="bx bx-plus"- text={t("automatic_replacements.custom_add")}- onClick={take}+ className="custom-replacement-remove"+ icon="bx bx-x"+ text={t("automatic_replacements.custom_remove")}+ onClick={() => save(replacements.filter((held) => held.from !== replacement.from))}/>- )}- </div>- </div>- </div>+ </CardSection>+ )),++ <CardSection key="entry" className="custom-replacement">+ {/* The two boxes and the button asking for what they hold are one thing on the+ page, so the focus is watched over the group rather than over each box. */}+ <div+ className="custom-replacement-entry"+ ref={entryRef}+ onFocusOut={(e) => {+ // Moving between the two boxes is not leaving the pair. Only a complete+ // one is taken on the way out: half of a replacement is not a+ // replacement, and storing it would put an entry in the set that could+ // never fire.+ if (e.relatedTarget instanceof Node && entryRef.current?.contains(e.relatedTarget)) return;+ if (isComplete) take();+ }}+ >+ <FormTextBox+ inputRef={fromRef}+ currentValue={draftFrom}+ placeholder={t("automatic_replacements.custom_from_placeholder")}+ onChange={setDraftFrom}+ onKeyDown={(e) => e.key === "Enter" && take()}+ />+ <span className="custom-replacement-arrow" aria-hidden="true">→</span>+ <FormTextBox+ currentValue={draftTo}+ placeholder={t("automatic_replacements.custom_to_placeholder")}+ onChange={setDraftTo}+ onKeyDown={(e) => e.key === "Enter" && take()}+ />++ {/* Enter takes the pair, but nothing on the page says so — so once there is+ a whole one to take, the same offer appears where it can be seen. */}+ {isComplete && (+ <ActionButton+ className="custom-replacement-add"+ icon="bx bx-plus"+ text={t("automatic_replacements.custom_add")}+ onClick={take}+ />+ )}+ </div>+ </CardSection>+ ]}+ />);}@@ -392,31 +424,42 @@ function Editor() {}, [headingStyle]);return (- <OptionsSection title={t("text_editor.title")}>- <OptionsRow name="heading-style" label={t("heading_style.title")} description={t("heading_style.description")}>- <HeadingStyleSelector currentValue={headingStyle} onChange={setHeadingStyle} />- </OptionsRow>-- <OptionsRow name="auto-readonly-size-text" label={t("text_auto_read_only_size.label")} description={t("text_auto_read_only_size.description")}>- <FormTextBoxWithUnit- type="number" min={0}- unit={t("text_auto_read_only_size.unit")}- currentValue={autoReadonlySize}- onBlur={setAutoReadonlySize}- />- </OptionsRow>-- <OptionsRow- name="custom-date-time-format"- label={t("custom_date_time_format.title")}- description={<>{t("custom_date_time_format.description_short")} {t("custom_date_time_format.preview", { preview: formatDateTime(new Date(), customDateTimeFormat) })}</>}- >- <FormTextBox- placeholder="YYYY-MM-DD HH:mm"- currentValue={customDateTimeFormat || "YYYY-MM-DD HH:mm"} onBlur={setCustomDateTimeFormat}- />- </OptionsRow>- </OptionsSection>+ <div className="options-section text-notes-editor">+ <Card heading={t("text_editor.title")}>+ <CardOption+ name="heading-style"+ label={t("heading_style.title")}+ description={t("heading_style.description")}+ >+ <HeadingStyleSelector currentValue={headingStyle} onChange={setHeadingStyle} />+ </CardOption>++ <CardOption+ className="text-notes-number"+ name="auto-readonly-size-text"+ label={t("text_auto_read_only_size.label")}+ description={t("text_auto_read_only_size.description")}+ >+ <FormTextBoxWithUnit+ type="number" min={0}+ unit={t("text_auto_read_only_size.unit")}+ currentValue={autoReadonlySize}+ onBlur={setAutoReadonlySize}+ />+ </CardOption>++ <CardOption+ name="custom-date-time-format"+ label={t("custom_date_time_format.title")}+ description={<>{t("custom_date_time_format.description_short")} {t("custom_date_time_format.preview", { preview: formatDateTime(new Date(), customDateTimeFormat) })}</>}+ >+ <FormTextBox+ placeholder="YYYY-MM-DD HH:mm"+ currentValue={customDateTimeFormat || "YYYY-MM-DD HH:mm"} onBlur={setCustomDateTimeFormat}+ />+ </CardOption>+ </Card>+ </div>);}@@ -519,56 +562,82 @@ function CodeBlockStyle() {}, [effectiveTheme]);return (- <OptionsSection title={t("highlighting.title")}>- <ThemeModeSelector matchesApp={matchesApp} onMatchesAppChange={setMatchesApp} />-- {matchesApp ? (- <>- <OptionsRow name="light-theme" label={t("code_theme.light_theme")}>- <FormSelect- values={lightThemes}- keyProperty="val" titleProperty="title"- currentValue={lightTheme} onChange={setLightTheme}- />- </OptionsRow>- <OptionsRow name="dark-theme" label={t("code_theme.dark_theme")}>- <FormSelect- values={darkThemes}+ <div className="options-section text-notes-code-blocks">+ <Card heading={t("highlighting.title")}>+ <ThemeModeOption matchesApp={matchesApp} onMatchesAppChange={setMatchesApp} />++ {matchesApp ? (+ <>+ <CardOption name="light-theme" label={t("code_theme.light_theme")}>+ <FormSelect+ values={lightThemes}+ keyProperty="val" titleProperty="title"+ currentValue={lightTheme} onChange={setLightTheme}+ />+ </CardOption>+ <CardOption name="dark-theme" label={t("code_theme.dark_theme")}>+ <FormSelect+ values={darkThemes}+ keyProperty="val" titleProperty="title"+ currentValue={darkTheme} onChange={setDarkTheme}+ />+ </CardOption>+ </>+ ) : (+ <CardOption name="code-block-theme" label={t("highlighting.color-scheme")}>+ <FormSelectWithGroups+ values={groupedThemes}keyProperty="val" titleProperty="title"- currentValue={darkTheme} onChange={setDarkTheme}+ currentValue={codeBlockTheme} onChange={setCodeBlockTheme}/>- </OptionsRow>- </>- ) : (- <OptionsRow name="code-block-theme" label={t("highlighting.color-scheme")}>- <FormSelectWithGroups- values={groupedThemes}- keyProperty="val" titleProperty="title"- currentValue={codeBlockTheme} onChange={setCodeBlockTheme}+ </CardOption>+ )}++ <CardOption name="code-block-word-wrap" label={t("code_block.word_wrapping")}>+ <FormToggle currentValue={codeBlockWordWrap} onChange={setCodeBlockWordWrap} />+ </CardOption>++ {/* Avoid using "code" in the name of numeric inputs to prevent KeepassXC from triggering. */}+ <CardOption className="text-notes-number" name="block-tab-width" label={t("code_block.tab_width")}>+ <FormTextBoxWithUnit+ type="number" min={1} max={16} step={1}+ unit={t("code_block.tab_width_unit")}+ currentValue={codeBlockTabWidth}+ onChange={setCodeBlockTabWidth}+ onBlur={setCodeBlockTabWidth}/>- </OptionsRow>- )}+ </CardOption>- <OptionsRowWithToggle- name="code-block-word-wrap"- label={t("code_block.word_wrapping")}- currentValue={codeBlockWordWrap}- onChange={setCodeBlockWordWrap}- />+ <CardSection className="code-block-preview">+ <CodeBlockPreview theme={effectiveTheme} wordWrap={codeBlockWordWrap} tabWidth={codeBlockTabWidth} />+ </CardSection>+ </Card>+ </div>+ );+}++type ThemeMode = "app" | "fixed";++/**+ * Whether the code block theme follows the app's own light and dark, or stays on one whatever the app+ * does. Kept here rather than taken from `ThemeModeSelector`, which still speaks in option rows for+ * the code notes page — the two rejoin once that page has cards of its own.+ */+function ThemeModeOption({ matchesApp, onMatchesAppChange }: { matchesApp: boolean, onMatchesAppChange: (value: boolean) => void }) {+ const modes: SegmentedChoiceOption<ThemeMode>[] = [+ { value: "app", label: t("code_theme.match_app_appearance"), icon: "bx-brightness-half" },+ { value: "fixed", label: t("code_theme.always_use_one_theme"), icon: "bx-pin" }+ ];- {/* Avoid using "code" in the name of numeric inputs to prevent KeepassXC from triggering. */}- <OptionsRow name="block-tab-width" label={t("code_block.tab_width")}>- <FormTextBoxWithUnit- type="number" min={1} max={16} step={1}- unit={t("code_block.tab_width_unit")}- currentValue={codeBlockTabWidth}- onChange={setCodeBlockTabWidth}- onBlur={setCodeBlockTabWidth}- />- </OptionsRow>-- <CodeBlockPreview theme={effectiveTheme} wordWrap={codeBlockWordWrap} tabWidth={codeBlockTabWidth} />- </OptionsSection>+ return (+ <CardOption name="theme-mode" label={t("code_theme.theme_mode")}>+ <SegmentedChoice+ options={modes}+ currentValue={matchesApp ? "app" : "fixed"}+ onChange={(mode) => onMatchesAppChange(mode === "app")}+ collapseOnMobile+ />+ </CardOption>);}@@ -633,37 +702,52 @@ function TableOfContent() {const [ minTocHeadings, setMinTocHeadings ] = useTriliumOption("minTocHeadings");return (!isNewLayout &&- <OptionsSection title={t("table_of_contents.title")}>- <FormText>{t("table_of_contents.description")}</FormText>-- <FormGroup name="min-toc-headings">- <FormTextBoxWithUnit- type="number"- min={0} max={999999999999999} step={1}- unit={t("table_of_contents.unit")}- currentValue={minTocHeadings} onChange={setMinTocHeadings}- />- </FormGroup>-- <FormText>{t("table_of_contents.disable_info")}</FormText>- <FormText>{t("table_of_contents.shortcut_info")}</FormText>- </OptionsSection>+ <div className="options-section text-notes-toc">+ <Card+ heading={t("table_of_contents.title")}+ description={t("table_of_contents.description")}+ >+ <CardSection className="text-notes-number">+ <FormGroup name="min-toc-headings">+ <FormTextBoxWithUnit+ type="number"+ min={0} max={999999999999999} step={1}+ unit={t("table_of_contents.unit")}+ currentValue={minTocHeadings} onChange={setMinTocHeadings}+ />+ </FormGroup>++ <FormText>{t("table_of_contents.disable_info")}</FormText>+ <FormText>{t("table_of_contents.shortcut_info")}</FormText>+ </CardSection>+ </Card>+ </div>);}function HighlightsList() {return (- <OptionsSection title={t("highlights_list.title")}>- <HighlightsListOptions />+ <>+ <div className="options-section text-notes-highlights">+ <Card heading={t("highlights_list.title")}>+ <CardSection>+ <HighlightsListOptions />+ </CardSection>+ </Card>+ </div>+ {/* Its own card rather than a heading inside the one above: what the list is made of and+ where it is shown are two subjects, and a card heading is what tells them apart. */}{!isNewLayout && (- <>- <hr />- <h5>{t("highlights_list.visibility_title")}</h5>- <FormText>{t("highlights_list.visibility_description")}</FormText>- <FormText>{t("highlights_list.shortcut_info")}</FormText>- </>+ <div className="options-section">+ <Card heading={t("highlights_list.visibility_title")}>+ <CardSection>+ <FormText>{t("highlights_list.visibility_description")}</FormText>+ <FormText>{t("highlights_list.shortcut_info")}</FormText>+ </CardSection>+ </Card>+ </div>)}- </OptionsSection>+ </>);}