Files
openidea/src/features/vcs/__tests__/viewerFont.test.ts
T
JawandClaude Opus 5.5 a20207110e fix(vcs): follow the editor font settings in diff and merge viewers (#253)
The VCS viewers (diff, merge, local history) hard-coded the default mono
font, size and line height, so Settings > Editor > Font had no effect on
them. Read the editor font variables like the main editor does, and apply
fontExtension next to the caret, kept in step with the settings.

Co-authored-by: Claude Opus 5.5 <[email protected]>
2026-10-29 19:43:40 +08:00

37 lines
1.6 KiB
TypeScript

import { afterEach, describe, expect, it } from "vitest";
import { EditorState } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
import { useProject } from "@/platform/project";
import type { Settings } from "@/platform/ipc";
import { viewerBase } from "../cm";
const previous = useProject.getState().settings;
const views: EditorView[] = [];
afterEach(() => {
views.splice(0).forEach((v) => v.destroy());
useProject.setState({ settings: previous });
});
const setEditor = (editor: object) => useProject.setState({ settings: { editor } as unknown as Settings });
describe("viewer font", () => {
it("follows the editor's font settings, also when they change", () => {
setEditor({ fontFamily: "Fira Code", fontSize: 16, lineHeight: 22 });
const view = new EditorView({
state: EditorState.create({ doc: "a", extensions: viewerBase({ readOnly: true }) }),
});
views.push(view);
const style = () => view.dom.style;
expect(style().getPropertyValue("--openidea-editor-font")).toContain("Fira Code");
expect(style().getPropertyValue("--openidea-editor-font-size")).toBe("16px");
expect(style().getPropertyValue("--openidea-editor-line-height")).toBe("22px");
expect(view.dom.classList.contains("cm-openidea-ligatures")).toBe(false);
setEditor({ fontSize: 11, ligatures: true });
expect(style().getPropertyValue("--openidea-editor-font")).toBe("");
expect(style().getPropertyValue("--openidea-editor-font-size")).toBe("11px");
expect(view.dom.classList.contains("cm-openidea-ligatures")).toBe(true);
});
});