fix(terminal): keep Latin text monospace when the chosen font is missing (#5958)

The terminal stack named the CJK fallback faces (since #5458) right after the Nerd Fonts. Their Latin glyphs are proportional, and past the bundled font the --font-mono stack only has macOS faces, so on Linux and Windows a chosen family that doesn't take left plain text drawn by Noto Sans CJK SC / Microsoft YaHei inside cells sized for its widest glyph. Common Linux/Windows monospace faces (DejaVu Sans Mono, Liberation Mono, Noto Sans Mono, Cascadia Mono, Consolas) now come before the CJK faces; none has CJK glyphs, so wide characters still reach the named CJK faces.

Fixes #5799
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-26 03:46:52 +08:00
1 джерело c9bb5a3169
коміт 2ba2f33232
3 files changed
+34 -4

No files matched your search

+12
Переглянути файл
@@ -467,6 +467,18 @@ describe("terminalFont", () => {
expect(family).toContain('"PingFang SC", "Noto Sans CJK SC", "Noto Sans SC", "Source Han Sans SC"');
expect(family.endsWith(', "Source Han Sans SC", monospace')).toBe(true);
});
it("names Latin monospace faces before the CJK ones, whose Latin glyphs are proportional", () => {
// A Linux box without the chosen font: Latin must stop at a monospace face, not Noto Sans CJK.
for (const font of [
terminalFont(t, editor, BASE),
terminalFont({ ...t, useEditorFont: false, fontFamily: "Missing Mono" }, editor, BASE),
]) {
const at = (face: string) => font.family.indexOf(`"${face}"`);
expect(at("DejaVu Sans Mono")).toBeGreaterThan(at("Symbols Nerd Font"));
expect(at("Consolas")).toBeLessThan(at("Microsoft YaHei"));
expect(at("DejaVu Sans Mono")).toBeLessThan(at("Noto Sans CJK SC"));
}
});
});
describe("terminal tab titles", () => {
+8 -4
Переглянути файл
@@ -8,6 +8,7 @@ import type { ITheme, Terminal } from "@xterm/xterm";
import { fontWeightOf } from "@/platform/editorSettings";
import {
CJK_FALLBACK_FACES,
LATIN_MONO_FALLBACK_FACES,
fontsLoaded,
monoStack,
nerdFontFaces,
@@ -186,13 +187,16 @@ export interface TerminalFont {
}
/**
* Nerd Fonts before the generic family, so per-glyph fallback finds prompt icons, then the CJK
* faces: a wide character xterm only finds through the webview's own fallback measures one way and
* draws another (see `CJK_FALLBACK_FACES`), which drifts any row that mixes CJK with a background.
* Nerd Fonts before the generic family, so per-glyph fallback finds prompt icons, then common
* Latin monospace faces (the CJK faces' Latin glyphs are proportional, see
* `LATIN_MONO_FALLBACK_FACES`), then the CJK faces: a wide character xterm only finds through the
* webview's own fallback measures one way and draws another (see `CJK_FALLBACK_FACES`), which
* drifts any row that mixes CJK with a background.
*/
function withNerdFonts(family: string): string {
const latin = LATIN_MONO_FALLBACK_FACES.map(quoteFontFamily).join(", ");
const cjk = CJK_FALLBACK_FACES.map(quoteFontFamily).join(", ");
return `${family.replace(/,\s*monospace\s*$/i, "")}, ${nerdFontFaces().join(", ")}, ${cjk}, monospace`;
return `${family.replace(/,\s*monospace\s*$/i, "")}, ${nerdFontFaces().join(", ")}, ${latin}, ${cjk}, monospace`;
}
/**
+14
Переглянути файл
@@ -139,6 +139,20 @@ export const CJK_FALLBACK_FACES = [
"Noto Sans SC",
"Source Han Sans SC",
];
/**
* Monospace faces Linux and Windows ship, named before `CJK_FALLBACK_FACES` on a grid's font
* stack. Those CJK faces carry proportional Latin glyphs: when the chosen family and the
* `--font-mono` stack (macOS-only past the bundled font) don't take, plain text would be drawn by
* one of them inside cells measured for its widest glyph, every letter adrift in a wide cell.
* None of these has CJK glyphs, so wide characters still reach the named CJK faces.
*/
export const LATIN_MONO_FALLBACK_FACES = [
"DejaVu Sans Mono",
"Liberation Mono",
"Noto Sans Mono",
"Cascadia Mono",
"Consolas",
];
/** In running text the proportional faces give icons their own width instead of one cell's. */
const UI_NERD_FONTS = [
"JetBrainsMono Nerd Font Propo",