Skip to content

Commit b6a5faa

Browse files
committed
fix(ui): preserve local font query receiver
1 parent 9172565 commit b6a5faa

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @vitest-environment jsdom
2+
3+
import { describe, expect, it, vi } from 'vitest';
4+
import { resolveTerminalFonts } from '../fonts';
5+
6+
describe('resolveTerminalFonts', () => {
7+
it('preserves the Window receiver while probing local fallbacks', async () => {
8+
const queryLocalFonts = vi.fn(function (this: Window) {
9+
expect(this).toBe(window);
10+
return Promise.resolve([
11+
{
12+
family: 'Hiragino Sans GB',
13+
fullName: 'Hiragino Sans GB W3',
14+
postscriptName: 'HiraginoSansGB-W3',
15+
},
16+
{
17+
family: 'Apple Color Emoji',
18+
fullName: 'Apple Color Emoji',
19+
postscriptName: 'AppleColorEmoji',
20+
},
21+
]);
22+
});
23+
Object.defineProperty(window, 'queryLocalFonts', {
24+
configurable: true,
25+
value: queryLocalFonts,
26+
});
27+
28+
const fonts = await resolveTerminalFonts('code-150-test');
29+
const families = fonts.flatMap((font) =>
30+
typeof font === 'object' && 'family' in font ? [font.family] : [],
31+
);
32+
33+
expect(queryLocalFonts).toHaveBeenCalledOnce();
34+
expect(families).toContain('Hiragino Sans GB');
35+
expect(families).toContain('Apple Color Emoji');
36+
});
37+
});

packages/presentation/ui/src/shell/terminal/fonts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async function queryLocalFontsSafe(): Promise<readonly LocalFontData[]> {
6969
const query = (window as { queryLocalFonts?: () => Promise<LocalFontData[]> }).queryLocalFonts;
7070
if (!query) return [];
7171
try {
72-
return await query();
72+
return await query.call(window);
7373
} catch {
7474
// Local Font Access denied or unavailable — bundled fonts still cover latin + mono emoji.
7575
return [];

0 commit comments

Comments
 (0)