Skip to content

Build your personal knowledge base with Trilium Notes

feat(fonts): drop the font picker's preview on mobile

Elian Doranbc65213f690e
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 f22e0eb063..233ccb57d2 100644
--- a/apps/client/src/widgets/type_widgets/options/appearance_fonts.css
+++ b/apps/client/src/widgets/type_widgets/options/appearance_fonts.css
@@ -58,6 +58,26 @@ body.desktop .modal.font-picker-modal {
}
}
+body.mobile .modal.font-picker-modal {
+ .modal-dialog {
+ height: 85vh;
+ }
+
+ .modal-content {
+ flex: 1 1 0;
+ min-height: 0;
+ }
+
+ .modal-content-with-sidebar > .modal-main {
+ flex: 0 0 auto;
+ }
+
+ .modal-content-with-sidebar > .modal-sidebar {
+ flex: 1 1 0;
+ height: auto;
+ }
+}
+
.modal.font-picker-modal {
/* Keep the sidebar background within the rounded corners. */
.modal-content {
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 1658940ce3..0175bf89da 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
@@ -7,6 +7,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({
electron: true,
+ mobile: false,
stored: {} as Record<string, string | boolean>,
userFonts: [] as { noteId: string; title: string; blobId: string }[],
systemFonts: [] as { family: string; monospace: boolean }[],
@@ -17,7 +18,8 @@ const mocks = vi.hoisted(() => ({
// Only the desktop app can be asked what fonts the device has.
vi.mock("../../../services/utils", async (importOriginal) => ({
...(await importOriginal<typeof import("../../../services/utils")>()),
- isElectron: () => mocks.electron
+ isElectron: () => mocks.electron,
+ isMobile: () => mocks.mobile
}));
vi.mock("../../../services/i18n", () => ({ t: (key: string) => key }));
@@ -58,6 +60,7 @@ let host: HTMLElement;
beforeEach(() => {
mocks.electron = true;
+ mocks.mobile = false;
mocks.stored = {};
mocks.userFonts = [];
mocks.systemFonts = [];
@@ -381,6 +384,15 @@ describe("the font settings", () => {
expect(sample?.textContent).toContain("<=");
});
+ it("leaves the preview out on mobile, where the font list needs the room", async () => {
+ mocks.mobile = true;
+ await openPicker();
+
+ expect(document.querySelector(".font-picker-modal .font-size-control")).not.toBeNull();
+ expect(listedFonts()).toEqual(expect.arrayContaining(GENERIC_LABELS));
+ expect(document.querySelector(".font-picker-modal .font-preview")).toBeNull();
+ });
+
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 382ea5ad33..bad3b1c223 100644
--- a/apps/client/src/widgets/type_widgets/options/appearance_fonts.tsx
+++ b/apps/client/src/widgets/type_widgets/options/appearance_fonts.tsx
@@ -10,7 +10,7 @@ import FNote from "../../../entities/fnote";
import { getCustomFonts, registerFontNote } from "../../../services/custom_fonts";
import { filterAvailableFamilies, listSystemFonts, quoteFamily, type SystemFont } from "../../../services/font";
import { t } from "../../../services/i18n";
-import { isElectron } from "../../../services/utils";
+import { isElectron, isMobile } from "../../../services/utils";
import Button from "../../react/Button";
import { Card, OptionCardSection } from "../../react/Card";
import { filterTokens, matchesFilter } from "../../react/filter";
@@ -633,18 +633,22 @@ function FontPickerModal({ show, onHidden, target, onTargetChange, option: { fam
{target.sizeDescription && <small className="font-size-description">{target.sizeDescription}</small>}
</div>
- <div className="font-preview">
- <label>{t("fonts.preview")}</label>
- <div
- className="font-preview-text"
- style={{
- fontFamily: cssFontFamily(target, family),
- fontSize: `${size}%`
- }}
- >
- {Preview ? <Preview /> : PREVIEW_TEXT}
+ {/* On mobile the list rows show each family and the change applies live, so the
+ list gets the room instead. */}
+ {!isMobile() && (
+ <div className="font-preview">
+ <label>{t("fonts.preview")}</label>
+ <div
+ className="font-preview-text"
+ style={{
+ fontFamily: cssFontFamily(target, family),
+ fontSize: `${size}%`
+ }}
+ >
+ {Preview ? <Preview /> : PREVIEW_TEXT}
+ </div>
</div>
- </div>
+ )}
</div>
</Modal>,
document.body