Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai e34a6020e1 fix(fonts): editor popups and consoles follow the configured fonts
- Completion, parameter info and hover docs render in a tooltip container
  outside the editor, which carries its theme classes but not its inline
  style, so they used the default mono font at 13px. The editor font
  variables are now also provided as a theme; completion rows grow with
  the font size.
- The Run and Debug consoles use the terminal's weights (the editor's main
  and bold weights when the terminal follows the editor font).
- "Show only monospaced fonts" is a setting shared by Editor › Font and
  Tools › Terminal instead of resetting every time the page opens.

Fixes #3621
2026-11-17 04:08:20 +08:00
14 змінених файлів з 116 додано та 28 видалено

No files matched your search

+15
Переглянути файл
@@ -920,6 +920,8 @@ pub struct EditorSettings {
/// Colours the rainbow bracket depth cycles through (2–5).
pub rainbow_bracket_colors: u32,
pub ligatures: bool,
/// Editor › Font and Tools › Terminal › Font: the font pickers list only monospaced fonts.
pub only_monospaced_fonts: bool,
/// Fallback font for glyphs the main font lacks; empty = none.
pub fallback_font: String,
/// Typography Settings › Main font weight (CSS 100–900), as IDEA.
@@ -966,6 +968,7 @@ impl Default for EditorSettings {
rainbow_bracket_kinds: RainbowBracketKinds::default(),
rainbow_bracket_colors: 3,
ligatures: false,
only_monospaced_fonts: true,
fallback_font: String::new(),
font_weight: 400,
bold_font_weight: 700,
@@ -1820,6 +1823,18 @@ mod tests {
assert_eq!(restored.editor.rainbow_bracket_colors, 5);
}
#[test]
fn only_monospaced_fonts_defaults_on_and_round_trips() {
let old: Settings = serde_json::from_str(r#"{"editor":{"ligatures":true}}"#).unwrap();
assert!(old.editor.only_monospaced_fonts);
let mut settings = Settings::default();
settings.editor.only_monospaced_fonts = false;
let json = serde_json::to_value(&settings).unwrap();
assert_eq!(json["editor"]["onlyMonospacedFonts"], false);
let restored: Settings = serde_json::from_value(json).unwrap();
assert!(!restored.editor.only_monospaced_fonts);
}
#[test]
fn docstring_format_defaults_and_round_trips() {
let old: Settings = serde_json::from_str(r#"{"editor":{"semanticHighlighting":true}}"#).unwrap();
+1
Переглянути файл
@@ -123,6 +123,7 @@ Settings › Appearance & Behavior › Appearance, unless noted.
| ---------------------------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------ |
| `fontFamily` / `fontSize` / `lineHeight` | `"JetBrains Mono"` / `13` / `22` | Editor › Font. |
| `ligatures` | `false` | **Enable ligatures**. |
| `onlyMonospacedFonts` | `true` | **Show only monospaced fonts** in the Editor › Font and Terminal font pickers. |
| `fallbackFont` | `""` | **Fallback font**. |
| `fontWeight` / `boldFontWeight` | `400` / `700` | **Main font weight**, **Bold font weight**. |
| `colorScheme` | `"theme-default"` | Editor color scheme; `theme-default` follows the UI theme, otherwise a theme id or an imported scheme. |
+1
Переглянути файл
@@ -123,6 +123,7 @@ exclude = ["**/.git", "**/node_modules", "**/target", "**/dist"]
| ---------------------------------------- | -------------------------------- | ---------------------------------------------------------------------------------- |
| `fontFamily` / `fontSize` / `lineHeight` | `"JetBrains Mono"` / `13` / `22` | 编辑器 › 字体。 |
| `ligatures` | `false` | **启用连字**。 |
| `onlyMonospacedFonts` | `true` | **仅显示等宽字体**(编辑器 › 字体和终端字体的选择列表)。 |
| `fallbackFont` | `""` | **备用字体**。 |
| `fontWeight` / `boldFontWeight` | `400` / `700` | **主字重**、**粗体字重**。 |
| `colorScheme` | `"theme-default"` | 编辑器配色方案;`theme-default` 跟随界面主题,也可以是主题 id 或导入的方案。 |
+4
Переглянути файл
@@ -5268,6 +5268,8 @@ export type EditorSettings_Deserialize = {
/** Colours the rainbow bracket depth cycles through (2–5). */
rainbowBracketColors?: number,
ligatures?: boolean,
/** Editor › Font and Tools › Terminal › Font: the font pickers list only monospaced fonts. */
onlyMonospacedFonts?: boolean,
/** Fallback font for glyphs the main font lacks; empty = none. */
fallbackFont?: string,
/** Typography Settings › Main font weight (CSS 100–900), as IDEA. */
@@ -5326,6 +5328,8 @@ export type EditorSettings_Serialize = {
/** Colours the rainbow bracket depth cycles through (2–5). */
rainbowBracketColors: number,
ligatures: boolean,
/** Editor › Font and Tools › Terminal › Font: the font pickers list only monospaced fonts. */
onlyMonospacedFonts: boolean,
/** Fallback font for glyphs the main font lacks; empty = none. */
fallbackFont: string,
/** Typography Settings › Main font weight (CSS 100–900), as IDEA. */
+18 -14
Переглянути файл
@@ -179,27 +179,31 @@ export const formatIndentFacet = Facet.define<EffectiveIndent | null>({
});
export function fontExtension(settings: EditorSettings | undefined): Extension {
const vars: string[] = [];
const vars: Record<string, string> = {};
const prefs = prefsOf(settings);
const family = settings?.fontFamily;
const fallback = prefs.fallbackFont.trim();
if ((family && family !== BUNDLED_MONO_FAMILY) || fallback) {
vars.push(`--openidea-editor-font: ${monoFontFamily(family, fallback, "var(--font-mono)")}`);
vars["--openidea-editor-font"] = monoFontFamily(family, fallback, "var(--font-mono)");
}
if (settings?.fontSize) {
vars["--openidea-editor-font-size"] = `${settings.fontSize}px`;
vars["--openidea-editor-base-size"] = `${settings.fontSize}px`;
}
if (settings?.lineHeight) {
vars["--openidea-editor-line-height"] = `${settings.lineHeight}px`;
vars["--openidea-editor-base-line"] = `${settings.lineHeight}px`;
}
if (settings?.fontSize)
vars.push(
`--openidea-editor-font-size: ${settings.fontSize}px`,
`--openidea-editor-base-size: ${settings.fontSize}px`,
);
if (settings?.lineHeight)
vars.push(
`--openidea-editor-line-height: ${settings.lineHeight}px`,
`--openidea-editor-base-line: ${settings.lineHeight}px`,
);
const attrs: Record<string, string> = {};
if (vars.length) attrs.style = vars.join("; ");
const entries = Object.entries(vars);
if (entries.length) attrs.style = entries.map(([k, v]) => `${k}: ${v}`).join("; ");
if (prefs.ligatures) attrs.class = "cm-openidea-ligatures";
return Object.keys(attrs).length ? EditorView.editorAttributes.of(attrs) : [];
return [
Object.keys(attrs).length ? EditorView.editorAttributes.of(attrs) : [],
// The same variables as a theme: tooltips (completion, parameter info, hover docs) render
// in a container outside the editor that carries its theme classes, not its attributes.
entries.length ? EditorView.theme({ "&": vars }) : [],
];
}
export function readOnlyExtension(readOnly: boolean): Extension {
+8 -6
Переглянути файл
@@ -17,6 +17,8 @@ const tooltipSurface = {
* the hover and signature tooltips.
*/
const completionRowMetrics = {
// Rows grow with the editor font size (lookup text uses the editor font, as typed text does).
"--cm-completion-row": "max(var(--h-list-row), calc(var(--openidea-editor-font-size, var(--fs-code)) * 1.7))",
"--cm-completion-edge": "4px",
"--cm-completion-inset": "6px",
"--cm-completion-icon": "16px",
@@ -100,7 +102,7 @@ export const lspTheme = EditorView.theme({
...completionRowMetrics,
fontFamily: "var(--openidea-editor-font, var(--font-mono))",
fontWeight: "var(--fw-code, 400)",
fontSize: "var(--fs-code)",
fontSize: "var(--openidea-editor-font-size, var(--fs-code))",
// CodeMirror anchors the popup at the completed word's start. Pull it left by one row's
// leading inset so the labels, not the icon column, sit on the text. CodeMirror's horizontal
// clamp measures the border box (margins excluded), so this offset sits outside its math:
@@ -117,15 +119,15 @@ export const lspTheme = EditorView.theme({
fontWeight: "var(--fw-code, 400)",
minWidth: "420px",
maxWidth: "min(720px, 80vw)",
maxHeight: "calc(var(--h-list-row) * 11 + 8px)",
maxHeight: "calc(var(--cm-completion-row) * 11 + 8px)",
padding: "4px 0",
},
".cm-tooltip.cm-tooltip-autocomplete.cm-lsp-completion > ul > li": {
display: "flex",
alignItems: "center",
gap: "var(--cm-completion-gap)",
height: "var(--h-list-row)",
lineHeight: "var(--h-list-row)",
height: "var(--cm-completion-row)",
lineHeight: "var(--cm-completion-row)",
margin: "0 var(--cm-completion-edge)",
padding: "0 8px 0 var(--cm-completion-inset)",
borderRadius: "var(--radius-small)",
@@ -265,11 +267,11 @@ export const lspTheme = EditorView.theme({
".cm-lsp-signature": {
fontFamily: "var(--openidea-editor-font, var(--font-mono))",
fontWeight: "var(--fw-code, 400)",
fontSize: "var(--fs-code)",
fontSize: "var(--openidea-editor-font-size, var(--fs-code))",
padding: "6px 10px",
maxWidth: "640px",
},
".cm-lsp-signature-row": { color: "var(--fg-subtle)", whiteSpace: "pre-wrap", lineHeight: "20px" },
".cm-lsp-signature-row": { color: "var(--fg-subtle)", whiteSpace: "pre-wrap", lineHeight: "max(20px, 1.5em)" },
".cm-lsp-signature-active": {
color: "var(--fg-strong)",
backgroundColor: "var(--bg-identifier-under-caret, color-mix(in srgb, var(--accent) 14%, transparent))",
+6 -1
Переглянути файл
@@ -123,7 +123,12 @@ export function DebugConsole({ session, interactive = true }: { session: DebugSe
// The debug console uses the same font as the Run console.
const consoleFont = useConsoleFont();
const { rowHeight } = consoleFont;
const fontStyle = { fontFamily: consoleFont.family, fontSize: `${consoleFont.size}px` };
const fontStyle = {
fontFamily: consoleFont.family,
fontSize: `${consoleFont.size}px`,
fontWeight: consoleFont.weight,
["--fw-code-bold" as string]: String(consoleFont.boldWeight),
};
// Settings › Console › Use soft wraps is the default; the toggle overrides it for this console.
const defaultWrap = useWorkflowSettings((s) => s.console.softWrap);
const logColors = useWorkflowSettings((s) => s.console.logColors);
+2
Переглянути файл
@@ -549,6 +549,8 @@ export function ConsoleView({
style={{
fontFamily: consoleFont.family,
fontSize: `${consoleFont.size}px`,
fontWeight: consoleFont.weight,
["--fw-code-bold" as string]: String(consoleFont.boldWeight),
lineHeight: `${rowHeight}px`,
}}
role="log"
+2 -1
Переглянути файл
@@ -17,7 +17,8 @@ import { tx } from "@/platform/i18n";
function FontRow() {
const [family, setFamily] = useSetting<string>("editor.fontFamily");
const [monoOnly, setMonoOnly] = useState(true);
const [monoSetting, setMonoOnly] = useSetting<boolean>("editor.onlyMonospacedFonts");
const monoOnly = monoSetting !== false;
const matched = useLabelMatch("Show only monospaced fonts");
return (
<Row label="Font">
+2 -1
Переглянути файл
@@ -259,7 +259,8 @@ function TerminalFont() {
const [columnWidth, setColumnWidth] = useSetting<number>("terminal.columnWidth");
const matched = useLabelMatch("Use editor font");
const monoMatched = useLabelMatch("Show only monospaced fonts");
const [monoOnly, setMonoOnly] = useState(true);
const [monoSetting, setMonoOnly] = useSetting<boolean>("editor.onlyMonospacedFonts");
const monoOnly = monoSetting !== false;
return (
<>
<div className={clsx(styles.inlineRow, matched && styles.matched)}>
+1
Переглянути файл
@@ -22,6 +22,7 @@ export const CLIENT_SETTINGS_KEYS = [
"editor.fontSize",
"editor.lineHeight",
"editor.ligatures",
"editor.onlyMonospacedFonts",
"editor.fallbackFont",
"editor.fontWeight",
"editor.boldFontWeight",
+24
Переглянути файл
@@ -0,0 +1,24 @@
import { describe, expect, it } from "vitest";
import { consoleFontOf } from "./consoleFont";
const terminal = (useEditorFont: boolean) => ({
useEditorFont,
fontFamily: "Menlo",
fallbackFontFamily: "",
fontSize: 13,
});
const editor = { fontFamily: "Fira Code", fontSize: 15, fontWeight: 500, boldFontWeight: 800 };
describe("console font", () => {
it("uses the editor's weights when the terminal follows the editor font", () => {
const font = consoleFontOf(terminal(true), editor);
expect(font).toMatchObject({ size: 15, weight: 500, boldWeight: 800 });
expect(font.family).toContain("Fira Code");
});
it("uses regular and bold with the terminal's own font, as the terminal does", () => {
const font = consoleFontOf(terminal(false), editor);
expect(font).toMatchObject({ size: 13, weight: 400, boldWeight: 700 });
expect(font.family).toContain("Menlo");
});
});
+30 -5
Переглянути файл
@@ -1,14 +1,39 @@
import { useProject } from "./project";
import { resolveMonoFont } from "./fonts";
import { resolveMonoFont, type EditorFontChoice, type MonoFontChoice } from "./fonts";
import { useWorkflowSettings } from "./workflowSettings";
import { fontWeightOf } from "./editorSettings";
export interface ConsoleFont {
family: string;
size: number;
rowHeight: number;
weight: number;
boldWeight: number;
}
/**
* The font of the Run and Debug consoles: Tools › Terminal › Font (which can follow
* Editor › Font), with the row height both consoles lay their lines out with.
* Editor › Font), with the row height both consoles lay their lines out with. The
* weights match the terminal's: the editor's main and bold weights when the terminal
* uses the editor font, else regular and bold.
*/
export function useConsoleFont(): { family: string; size: number; rowHeight: number } {
export function consoleFontOf(
terminal: MonoFontChoice | undefined,
editor: (EditorFontChoice & { fontWeight?: number | null; boldFontWeight?: number | null }) | undefined,
): ConsoleFont {
const { family, size } = resolveMonoFont(terminal, editor);
const useEditor = !!terminal?.useEditorFont;
return {
family,
size,
rowHeight: Math.max(16, Math.round(size * 1.5)),
weight: useEditor ? fontWeightOf(editor?.fontWeight, 400) : 400,
boldWeight: useEditor ? fontWeightOf(editor?.boldFontWeight, 700) : 700,
};
}
export function useConsoleFont(): ConsoleFont {
const terminalFont = useWorkflowSettings((s) => s.terminal);
const editorFont = useProject((s) => s.settings?.editor);
const { family, size } = resolveMonoFont(terminalFont, editorFont);
return { family, size, rowHeight: Math.max(16, Math.round(size * 1.5)) };
return consoleFontOf(terminalFont, editorFont);
}
+2
Переглянути файл
@@ -83,6 +83,8 @@ export const EDITOR_EXTRA_DEFAULTS = {
/** Colours the rainbow bracket depth cycles through (2–5). */
rainbowBracketColors: 3,
ligatures: false,
/** Editor › Font / Tools › Terminal › Font: the font pickers list only monospaced fonts. */
onlyMonospacedFonts: true,
fallbackFont: "",
/** Typography Settings › Main / Bold font weight (CSS weights, IDEA's Regular / Bold). */
fontWeight: 400,