дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-08 19:02:17 +02:00
The font pickers (editor, fallback, UI, terminal) become editable comboboxes: type to search installed families or enter any family name, and Refresh re-reads the system fonts. ide-fonts' cached family list is now refreshable (DirectWrite re-queries the system collection with checkForUpdates; CoreText and fontconfig are read anew), exposed through system_font_families(refresh). Before the first native result the pickers fall back to Canvas detection of common families; saved names and the last catalog are kept when a refresh fails. Fonts are enumerated on the local desktop in remote-development windows too. Co-authored-by: bghtyu <[email protected]>
37 рядки
1.5 KiB
TypeScript
37 рядки
1.5 KiB
TypeScript
import { afterEach, expect, it, vi } from "vitest";
|
|
import { detectCandidateFonts } from "./candidateFonts";
|
|
|
|
afterEach(() => vi.restoreAllMocks());
|
|
it("probes the legacy list and classifies measured mono and proportional families", () => {
|
|
const ctx = {
|
|
font: "",
|
|
measureText(text: string) {
|
|
if (this.font.includes('"Menlo"')) return { width: 120 };
|
|
if (this.font.includes('"Georgia"')) return { width: text.startsWith("i") ? 60 : 180 };
|
|
return { width: 100 };
|
|
},
|
|
};
|
|
vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue(ctx as unknown as CanvasRenderingContext2D);
|
|
expect(detectCandidateFonts()).toEqual([
|
|
{ name: "Menlo", monospaced: true },
|
|
{ name: "Georgia", monospaced: false },
|
|
]);
|
|
});
|
|
it("returns no inferred families when Canvas is absent", () => {
|
|
vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue(null);
|
|
expect(detectCandidateFonts()).toEqual([]);
|
|
});
|
|
it("contains failures from Canvas and never claims candidates are installed", () => {
|
|
vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockImplementation(() => {
|
|
throw new Error("disabled");
|
|
});
|
|
expect(detectCandidateFonts()).toEqual([]);
|
|
});
|
|
it("does not treat invalid measurements as available fonts", () => {
|
|
vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue({
|
|
font: "",
|
|
measureText: () => ({ width: Number.NaN }),
|
|
} as unknown as CanvasRenderingContext2D);
|
|
expect(detectCandidateFonts()).toEqual([]);
|
|
});
|