Skip to content

Build your personal knowledge base with Trilium Notes

feat(fonts): preview the monospace font on a piece of code

Elian Doran819cb5043475
diff --git a/apps/client/src/widgets/type_widgets/options/appearance_fonts.css b/apps/client/src/widgets/type_widgets/options/appearance_fonts.css
index 9025181945..948ffecbc3 100644
--- a/apps/client/src/widgets/type_widgets/options/appearance_fonts.css
+++ b/apps/client/src/widgets/type_widgets/options/appearance_fonts.css
@@ -179,6 +179,10 @@ body.desktop .modal.font-picker-modal {
line-height: 1.6;
}
+pre.font-preview-code {
+ padding: 0;
+}
+
/* Sized in em, so the heading keeps its proportion to the text under it as the slider moves. */
.font-preview-document {
h3 {
diff --git a/apps/client/src/widgets/type_widgets/options/appearance_fonts.spec.tsx b/apps/client/src/widgets/type_widgets/options/appearance_fonts.spec.tsx
index ba355e469f..515eb6c0b7 100644
--- a/apps/client/src/widgets/type_widgets/options/appearance_fonts.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/appearance_fonts.spec.tsx
@@ -334,6 +334,20 @@ describe("the font settings", () => {
expect(catalogue.fonts.document_preview_body).toContain("<em>");
});
+ it("shows the code sample on a surface the ligature setting reaches", async () => {
+ await openPicker();
+ await act(async () => pickerTargets()[3].click());
+
+ // `pre` is what `style.css` turns ligatures off on, so the sample answers to the setting
+ // sitting under the fonts; it is also what keeps the indentation the sample is written in.
+ const sample = document.querySelector(".font-preview-code");
+ expect(sample?.tagName).toBe("PRE");
+ // The pairs a family with programming ligatures draws as one glyph, which is what there is
+ // to look at when that setting is turned off and on.
+ expect(sample?.textContent).toContain("=>");
+ expect(sample?.textContent).toContain("<=");
+ });
+
it("leaves ligatures alone, since they come from the theme's own font", () => {
open();
diff --git a/apps/client/src/widgets/type_widgets/options/appearance_fonts.tsx b/apps/client/src/widgets/type_widgets/options/appearance_fonts.tsx
index bf3160f1b1..53442aa3d4 100644
--- a/apps/client/src/widgets/type_widgets/options/appearance_fonts.tsx
+++ b/apps/client/src/widgets/type_widgets/options/appearance_fonts.tsx
@@ -124,7 +124,8 @@ const FONT_TARGETS: FontTarget[] = [
shortLabel: t("fonts.monospace_font_short"),
description: t("fonts.monospace_font_description"),
themeVariable: "var(--monospace-font-family)",
- isMonospace: true
+ isMonospace: true,
+ Preview: CodePreview
}
];
@@ -476,6 +477,21 @@ function DocumentPreview() {
);
}
+/** The plot names set `0` against `O` and `1` against `l`; the operators are ligature pairs. */
+const CODE_PREVIEW = `const PLOTS = ["01", "10", "11"];
+
+/** Days until a stem in \`plot\` rooted, or null if it never did. */
+function rootedAfter(log, plot = PLOTS[0]) {
+ const entry = log.find(({ id }) => id === plot);
+ if (!entry || entry.days <= 0) return null;
+
+ return \`\${entry.days} days => \${entry.roots ?? 0} roots\`;
+}`;
+
+function CodePreview() {
+ return <pre className="font-preview-code">{CODE_PREVIEW}</pre>;
+}
+
const PREVIEW_TEXT = "The quick brown fox jumps over the lazy dog. 0123456789";
interface FontPickerModalProps {