дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-28 13:32:29 +02:00
feat(agents): add separate chat and code font settings (#6395)
Settings > Agents > Chat gets Font and Code Font groups like Terminal's: chat text and code each take a family, a fallback and a size. Defaults follow the interface font and the built-in code font, so nothing changes until a choice is made. Chat zoom steps on top of the chosen size, and a chosen code size also applies to fenced code blocks while inline code stays with the chat text. Co-authored-by: happut <[email protected]>
Цей коміт міститься в:
1 джерело
924bf6d3b9
коміт
a6d135d66f
13 files changed
+441
-31
No files matched your search
@@ -99,6 +99,20 @@ pub struct AgentSettings {
|
||||
pub smooth_text: bool,
|
||||
/// Conversations and the composer expand to the full width of the pane instead of staying in a centred column.
|
||||
pub fit_window_width: bool,
|
||||
/// Chat text follows the interface font (Appearance › Use custom font).
|
||||
pub chat_use_ui_font: bool,
|
||||
/// Chat text family when it does not follow the interface font.
|
||||
pub chat_font_family: String,
|
||||
/// Covers characters the chat font lacks.
|
||||
pub chat_font_fallback: String,
|
||||
pub chat_font_size: u32,
|
||||
/// Code in chat follows the built-in code font.
|
||||
pub code_use_default_font: bool,
|
||||
/// Code family when it does not follow the built-in code font.
|
||||
pub code_font_family: String,
|
||||
/// Covers characters the code font lacks.
|
||||
pub code_font_fallback: String,
|
||||
pub code_font_size: u32,
|
||||
#[serde(deserialize_with = "or_default")]
|
||||
#[specta(type = ThinkingDisplay)]
|
||||
pub thinking: ThinkingDisplay,
|
||||
@@ -145,6 +159,14 @@ impl Default for AgentSettings {
|
||||
show_cost: false,
|
||||
smooth_text: true,
|
||||
fit_window_width: false,
|
||||
chat_use_ui_font: true,
|
||||
chat_font_family: "Inter".into(),
|
||||
chat_font_fallback: String::new(),
|
||||
chat_font_size: 13,
|
||||
code_use_default_font: true,
|
||||
code_font_family: "JetBrains Mono".into(),
|
||||
code_font_fallback: String::new(),
|
||||
code_font_size: 13,
|
||||
thinking: ThinkingDisplay::Auto,
|
||||
tool_calls: ToolCallDisplay::Grouped,
|
||||
expand_tool_output: false,
|
||||
|
||||
@@ -3174,6 +3174,20 @@ export type AgentSettings_Deserialize = {
|
||||
smoothText?: boolean,
|
||||
/** Conversations and the composer expand to the full width of the pane instead of staying in a centred column. */
|
||||
fitWindowWidth?: boolean,
|
||||
/** Chat text follows the interface font (Appearance › Use custom font). */
|
||||
chatUseUiFont?: boolean,
|
||||
/** Chat text family when it does not follow the interface font. */
|
||||
chatFontFamily?: string,
|
||||
/** Covers characters the chat font lacks. */
|
||||
chatFontFallback?: string,
|
||||
chatFontSize?: number,
|
||||
/** Code in chat follows the built-in code font. */
|
||||
codeUseDefaultFont?: boolean,
|
||||
/** Code family when it does not follow the built-in code font. */
|
||||
codeFontFamily?: string,
|
||||
/** Covers characters the code font lacks. */
|
||||
codeFontFallback?: string,
|
||||
codeFontSize?: number,
|
||||
thinking?: ThinkingDisplay,
|
||||
toolCalls?: ToolCallDisplay,
|
||||
/** A tool call's output (a command's, a diff) is shown without opening it. */
|
||||
@@ -3217,6 +3231,20 @@ export type AgentSettings_Serialize = {
|
||||
smoothText: boolean,
|
||||
/** Conversations and the composer expand to the full width of the pane instead of staying in a centred column. */
|
||||
fitWindowWidth: boolean,
|
||||
/** Chat text follows the interface font (Appearance › Use custom font). */
|
||||
chatUseUiFont: boolean,
|
||||
/** Chat text family when it does not follow the interface font. */
|
||||
chatFontFamily: string,
|
||||
/** Covers characters the chat font lacks. */
|
||||
chatFontFallback: string,
|
||||
chatFontSize: number,
|
||||
/** Code in chat follows the built-in code font. */
|
||||
codeUseDefaultFont: boolean,
|
||||
/** Code family when it does not follow the built-in code font. */
|
||||
codeFontFamily: string,
|
||||
/** Covers characters the code font lacks. */
|
||||
codeFontFallback: string,
|
||||
codeFontSize: number,
|
||||
thinking: ThinkingDisplay,
|
||||
toolCalls: ToolCallDisplay,
|
||||
/** A tool call's output (a command's, a diff) is shown without opening it. */
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
padding: 24px 24px 12vh;
|
||||
background: var(--bg-editor);
|
||||
color: var(--fg);
|
||||
font-family: var(--agent-font-ui, var(--font-ui));
|
||||
}
|
||||
.inner {
|
||||
/* A compact block in the middle of the page: narrower than a session's conversation. */
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
background: var(--bg-app);
|
||||
color: var(--fg);
|
||||
font-size: var(--fs-ui);
|
||||
font-family: var(--agent-font-ui, var(--font-ui));
|
||||
font-size: var(--agent-fs-ui);
|
||||
}
|
||||
|
||||
.conversation {
|
||||
@@ -523,7 +524,7 @@
|
||||
transform: translateX(0);
|
||||
}
|
||||
.markdown :global(code) {
|
||||
font-family: var(--font-mono);
|
||||
font-family: var(--agent-font-code, var(--font-mono));
|
||||
font-size: var(--agent-fs-small, var(--fs-small));
|
||||
border-radius: var(--radius-small);
|
||||
background: var(--md-code-bg);
|
||||
@@ -543,6 +544,8 @@
|
||||
display: block;
|
||||
background: none;
|
||||
box-shadow: none;
|
||||
/* A chosen code size wins over the chat-derived one; inline code stays with the chat. */
|
||||
font-size: var(--agent-fs-code-chosen, var(--agent-fs-small, var(--fs-small)));
|
||||
}
|
||||
.codeBlock {
|
||||
position: relative;
|
||||
@@ -635,7 +638,7 @@
|
||||
border-radius: var(--radius-small);
|
||||
background: var(--bg-elev);
|
||||
color: var(--danger);
|
||||
font-family: var(--font-mono);
|
||||
font-family: var(--agent-font-code, var(--font-mono));
|
||||
font-size: var(--agent-fs-small, var(--fs-small));
|
||||
text-align: left;
|
||||
white-space: pre-wrap;
|
||||
@@ -939,7 +942,7 @@
|
||||
border-radius: var(--radius-small);
|
||||
border: 1px solid var(--border);
|
||||
background: var(--bg-elev);
|
||||
font-family: var(--font-mono);
|
||||
font-family: var(--agent-font-code, var(--font-mono));
|
||||
font-size: var(--agent-fs-small, var(--fs-small));
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
@@ -1006,7 +1009,7 @@
|
||||
border-radius: var(--radius-small);
|
||||
background: var(--bg-editor);
|
||||
color: var(--fg);
|
||||
font-family: var(--font-mono);
|
||||
font-family: var(--agent-font-code, var(--font-mono));
|
||||
font-size: var(--agent-fs-code, var(--fs-code));
|
||||
line-height: calc(var(--lh-code) + var(--agent-font-zoom, 0px) * 1.6);
|
||||
white-space: pre-wrap;
|
||||
@@ -1045,7 +1048,7 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-family: var(--font-mono);
|
||||
font-family: var(--agent-font-code, var(--font-mono));
|
||||
font-size: var(--agent-fs-small, var(--fs-small));
|
||||
}
|
||||
.permissionDone {
|
||||
@@ -1385,7 +1388,7 @@
|
||||
.changeCommitHash {
|
||||
flex: none;
|
||||
color: var(--fg-subtle);
|
||||
font-family: var(--font-mono);
|
||||
font-family: var(--agent-font-code, var(--font-mono));
|
||||
}
|
||||
.changeCommitSummary {
|
||||
flex: 1 1 0;
|
||||
@@ -1469,7 +1472,7 @@
|
||||
.subagentActivity {
|
||||
padding-left: 22px;
|
||||
color: var(--fg-muted);
|
||||
font-family: var(--font-mono);
|
||||
font-family: var(--agent-font-code, var(--font-mono));
|
||||
font-size: var(--agent-fs-small, var(--fs-small));
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
@@ -1769,7 +1772,7 @@
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-small);
|
||||
background: var(--bg-editor);
|
||||
font-family: var(--font-mono);
|
||||
font-family: var(--agent-font-code, var(--font-mono));
|
||||
font-size: var(--agent-fs-code, var(--fs-code));
|
||||
}
|
||||
.questionPreviewEmpty {
|
||||
@@ -1949,7 +1952,7 @@
|
||||
.exitCode {
|
||||
flex: none;
|
||||
color: var(--danger);
|
||||
font-family: var(--font-mono);
|
||||
font-family: var(--agent-font-code, var(--font-mono));
|
||||
font-size: var(--agent-fs-small, var(--fs-small));
|
||||
}
|
||||
.terminalBlock {
|
||||
@@ -1963,7 +1966,7 @@
|
||||
.terminalOutput {
|
||||
margin: 0;
|
||||
padding: 6px 10px;
|
||||
font-family: var(--font-mono);
|
||||
font-family: var(--agent-font-code, var(--font-mono));
|
||||
font-size: var(--agent-fs-small, var(--fs-small));
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
|
||||
@@ -12,6 +12,14 @@ export const AGENT_SETTINGS_DEFAULTS: ResolvedAgentSettings = {
|
||||
showCost: false,
|
||||
smoothText: true,
|
||||
fitWindowWidth: false,
|
||||
chatUseUiFont: true,
|
||||
chatFontFamily: "Inter",
|
||||
chatFontFallback: "",
|
||||
chatFontSize: 13,
|
||||
codeUseDefaultFont: true,
|
||||
codeFontFamily: "JetBrains Mono",
|
||||
codeFontFallback: "",
|
||||
codeFontSize: 13,
|
||||
thinking: "auto",
|
||||
toolCalls: "grouped",
|
||||
expandToolOutput: false,
|
||||
|
||||
@@ -55,7 +55,10 @@ vi.mock("@/platform/ipc", async (original) => ({
|
||||
},
|
||||
agentEntries: async () => ({ status: "ok", data: [] as AgentEntry[] }),
|
||||
agentChanges: async () => ({ status: "ok", data: [] }),
|
||||
agentGroupedChanges: async () => ({ status: "ok", data: { uncommitted: [], commits: [] } }),
|
||||
agentGroupedChanges: async () => ({
|
||||
status: "ok",
|
||||
data: { uncommitted: [], commits: [] },
|
||||
}),
|
||||
agentProviders: async () => ({ status: "ok", data: [] }),
|
||||
vcsBranchInfo: async () => ({ status: "ok", data: { head: "main" } }),
|
||||
vcsBranches: async () => ({ status: "ok", data: [] }),
|
||||
@@ -94,9 +97,19 @@ describe("Agent chat font size zoom", () => {
|
||||
resetAllAgentFontZoom();
|
||||
imageReads.clear();
|
||||
disposers.push(registerEditorActions());
|
||||
useContextKeys.setState({ projectOpen: true, textEditorActive: false, editorFocus: true, popupOpen: false });
|
||||
useContextKeys.setState({
|
||||
projectOpen: true,
|
||||
textEditorActive: false,
|
||||
editorFocus: true,
|
||||
popupOpen: false,
|
||||
});
|
||||
useProject.setState({
|
||||
project: { name: "openidea", root: "/project", isGit: true, workspace: null } as never,
|
||||
project: {
|
||||
name: "openidea",
|
||||
root: "/project",
|
||||
isGit: true,
|
||||
workspace: null,
|
||||
} as never,
|
||||
settings: null,
|
||||
});
|
||||
const t1 = makeTask("t1");
|
||||
@@ -132,13 +145,25 @@ describe("Agent chat font size zoom", () => {
|
||||
<div data-editor-focus="" tabIndex={-1}>
|
||||
<EditorTabIdProvider value="tab-1">
|
||||
<EditorShownProvider value={true}>
|
||||
<SessionEditor input={{ kind: SESSION_KIND, key: sessionKey("t1"), data: { task: "t1" } }} />
|
||||
<SessionEditor
|
||||
input={{
|
||||
kind: SESSION_KIND,
|
||||
key: sessionKey("t1"),
|
||||
data: { task: "t1" },
|
||||
}}
|
||||
/>
|
||||
</EditorShownProvider>
|
||||
</EditorTabIdProvider>
|
||||
</div>
|
||||
<EditorTabIdProvider value="tab-kept">
|
||||
<EditorShownProvider value={false}>
|
||||
<SessionEditor input={{ kind: SESSION_KIND, key: sessionKey("t2"), data: { task: "t2" } }} />
|
||||
<SessionEditor
|
||||
input={{
|
||||
kind: SESSION_KIND,
|
||||
key: sessionKey("t2"),
|
||||
data: { task: "t2" },
|
||||
}}
|
||||
/>
|
||||
</EditorShownProvider>
|
||||
</EditorTabIdProvider>
|
||||
</div>
|
||||
@@ -146,7 +171,13 @@ describe("Agent chat font size zoom", () => {
|
||||
<div data-editor-focus="" tabIndex={-1}>
|
||||
<EditorTabIdProvider value="tab-2">
|
||||
<EditorShownProvider value={true}>
|
||||
<SessionEditor input={{ kind: SESSION_KIND, key: sessionKey("t1"), data: { task: "t1" } }} />
|
||||
<SessionEditor
|
||||
input={{
|
||||
kind: SESSION_KIND,
|
||||
key: sessionKey("t1"),
|
||||
data: { task: "t1" },
|
||||
}}
|
||||
/>
|
||||
</EditorShownProvider>
|
||||
</EditorTabIdProvider>
|
||||
</div>
|
||||
@@ -223,7 +254,12 @@ describe("Agent chat font size zoom", () => {
|
||||
uiMode: null,
|
||||
readOnly: false,
|
||||
};
|
||||
const view = new EditorView({ state: EditorState.create({ doc: "const x = 1;", extensions: [cmFontZoom] }) });
|
||||
const view = new EditorView({
|
||||
state: EditorState.create({
|
||||
doc: "const x = 1;",
|
||||
extensions: [cmFontZoom],
|
||||
}),
|
||||
});
|
||||
document.body.appendChild(view.dom);
|
||||
const handle = { view, ctx };
|
||||
_addEditor(handle);
|
||||
@@ -235,7 +271,14 @@ describe("Agent chat font size zoom", () => {
|
||||
activeSlot = { view, disposed: false };
|
||||
|
||||
const { container } = render(
|
||||
<SessionEditor docked input={{ kind: SESSION_KIND, key: sessionKey("t1"), data: { task: "t1" } }} />,
|
||||
<SessionEditor
|
||||
docked
|
||||
input={{
|
||||
kind: SESSION_KIND,
|
||||
key: sessionKey("t1"),
|
||||
data: { task: "t1" },
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
const stream = container.querySelector<HTMLElement>(`.${styles.stream}`)!;
|
||||
|
||||
@@ -270,17 +313,34 @@ describe("Agent chat font size zoom", () => {
|
||||
const { container } = render(
|
||||
<div>
|
||||
<EditorTabIdProvider value="tab-1">
|
||||
<SessionEditor input={{ kind: SESSION_KIND, key: sessionKey("t1"), data: { task: "t1" } }} />
|
||||
<SessionEditor
|
||||
input={{
|
||||
kind: SESSION_KIND,
|
||||
key: sessionKey("t1"),
|
||||
data: { task: "t1" },
|
||||
}}
|
||||
/>
|
||||
</EditorTabIdProvider>
|
||||
<EditorTabIdProvider value="tab-2">
|
||||
<SessionEditor input={{ kind: SESSION_KIND, key: sessionKey("t2"), data: { task: "t2" } }} />
|
||||
<SessionEditor
|
||||
input={{
|
||||
kind: SESSION_KIND,
|
||||
key: sessionKey("t2"),
|
||||
data: { task: "t2" },
|
||||
}}
|
||||
/>
|
||||
</EditorTabIdProvider>
|
||||
</div>,
|
||||
);
|
||||
const streams = container.querySelectorAll<HTMLElement>(`.${styles.stream}`);
|
||||
const stream1 = streams[0]!;
|
||||
|
||||
const offEvent = new WheelEvent("wheel", { bubbles: true, cancelable: true, metaKey: true, deltaY: -100 });
|
||||
const offEvent = new WheelEvent("wheel", {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
metaKey: true,
|
||||
deltaY: -100,
|
||||
});
|
||||
act(() => {
|
||||
stream1.dispatchEvent(offEvent);
|
||||
});
|
||||
@@ -294,21 +354,35 @@ describe("Agent chat font size zoom", () => {
|
||||
})),
|
||||
);
|
||||
|
||||
const up = new WheelEvent("wheel", { bubbles: true, cancelable: true, metaKey: true, deltaY: -100 });
|
||||
const up = new WheelEvent("wheel", {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
metaKey: true,
|
||||
deltaY: -100,
|
||||
});
|
||||
act(() => {
|
||||
stream1.dispatchEvent(up);
|
||||
});
|
||||
expect(up.defaultPrevented).toBe(true);
|
||||
expect(useAgentFontZoom.getState().bySurface).toEqual({ "tab:tab-1": 1 });
|
||||
|
||||
const down = new WheelEvent("wheel", { bubbles: true, cancelable: true, ctrlKey: true, deltaY: 100 });
|
||||
const down = new WheelEvent("wheel", {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
ctrlKey: true,
|
||||
deltaY: 100,
|
||||
});
|
||||
act(() => {
|
||||
stream1.dispatchEvent(down);
|
||||
});
|
||||
expect(down.defaultPrevented).toBe(true);
|
||||
expect(useAgentFontZoom.getState().bySurface).toEqual({});
|
||||
|
||||
const plain = new WheelEvent("wheel", { bubbles: true, cancelable: true, deltaY: -100 });
|
||||
const plain = new WheelEvent("wheel", {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
deltaY: -100,
|
||||
});
|
||||
act(() => {
|
||||
stream1.dispatchEvent(plain);
|
||||
});
|
||||
@@ -324,13 +398,29 @@ describe("Agent chat font size zoom", () => {
|
||||
act(() =>
|
||||
useAgents.setState((s) => ({
|
||||
...s,
|
||||
entries: new Map([["t1", [{ type: "agent", text: "\n\n" }]]]),
|
||||
entries: new Map([
|
||||
[
|
||||
"t1",
|
||||
[
|
||||
{
|
||||
type: "agent",
|
||||
text: "\n\n",
|
||||
},
|
||||
],
|
||||
],
|
||||
]),
|
||||
})),
|
||||
);
|
||||
|
||||
const { container } = render(
|
||||
<EditorShownProvider value={true}>
|
||||
<SessionEditor input={{ kind: SESSION_KIND, key: sessionKey("t1"), data: { task: "t1" } }} />
|
||||
<SessionEditor
|
||||
input={{
|
||||
kind: SESSION_KIND,
|
||||
key: sessionKey("t1"),
|
||||
data: { task: "t1" },
|
||||
}}
|
||||
/>
|
||||
</EditorShownProvider>,
|
||||
);
|
||||
|
||||
@@ -344,8 +434,14 @@ describe("Agent chat font size zoom", () => {
|
||||
expect(diag.style.getPropertyValue("--image-width")).toBe("320px");
|
||||
|
||||
const shot = container.querySelector<HTMLImageElement>('img[alt="Shot"]')!;
|
||||
Object.defineProperty(shot, "naturalWidth", { value: 640, configurable: true });
|
||||
Object.defineProperty(shot, "naturalHeight", { value: 360, configurable: true });
|
||||
Object.defineProperty(shot, "naturalWidth", {
|
||||
value: 640,
|
||||
configurable: true,
|
||||
});
|
||||
Object.defineProperty(shot, "naturalHeight", {
|
||||
value: 360,
|
||||
configurable: true,
|
||||
});
|
||||
act(() => {
|
||||
shot.dispatchEvent(new Event("load"));
|
||||
});
|
||||
@@ -353,6 +449,54 @@ describe("Agent chat font size zoom", () => {
|
||||
expect(shot.style.getPropertyValue("--image-width")).toBe("640px");
|
||||
});
|
||||
|
||||
it("applies the Agents › Chat font choices as surface variables, with zoom on top of the chosen size", () => {
|
||||
const { container } = render(
|
||||
<EditorShownProvider value={true}>
|
||||
<SessionEditor
|
||||
input={{
|
||||
kind: SESSION_KIND,
|
||||
key: sessionKey("t1"),
|
||||
data: { task: "t1" },
|
||||
}}
|
||||
/>
|
||||
</EditorShownProvider>,
|
||||
);
|
||||
const session = container.querySelector<HTMLElement>(`.${styles.session}`)!;
|
||||
// Defaults follow the interface and built-in code fonts: no surface overrides.
|
||||
expect(session.style.getPropertyValue("--agent-font-ui")).toBe("");
|
||||
expect(session.style.getPropertyValue("--agent-font-code")).toBe("");
|
||||
expect(session.style.getPropertyValue("--agent-fs-code-chosen")).toBe("");
|
||||
|
||||
act(() =>
|
||||
useProject.setState((s) => ({
|
||||
...s,
|
||||
settings: {
|
||||
agents: {
|
||||
chatUseUiFont: false,
|
||||
chatFontFamily: "Maple Mono NF CN",
|
||||
chatFontFallback: "PingFang SC",
|
||||
chatFontSize: 16,
|
||||
codeUseDefaultFont: false,
|
||||
codeFontFamily: "Hack",
|
||||
codeFontSize: 15,
|
||||
},
|
||||
} as never,
|
||||
})),
|
||||
);
|
||||
expect(session.style.getPropertyValue("--agent-font-ui")).toContain('"Maple Mono NF CN"');
|
||||
expect(session.style.getPropertyValue("--agent-font-ui")).toContain('"PingFang SC"');
|
||||
expect(session.style.getPropertyValue("--agent-fs-ui")).toBe("calc(16px + var(--agent-font-zoom, 0px))");
|
||||
expect(session.style.getPropertyValue("--agent-fs-small")).toBe("calc(15px + var(--agent-font-zoom, 0px))");
|
||||
expect(session.style.getPropertyValue("--agent-font-code")).toContain('"Hack"');
|
||||
expect(session.style.getPropertyValue("--agent-fs-code")).toBe("calc(15px + var(--agent-font-zoom, 0px))");
|
||||
expect(session.style.getPropertyValue("--agent-fs-code-chosen")).toBe("var(--agent-fs-code)");
|
||||
expect(session.style.getPropertyValue("--lh-code")).toBe("25px");
|
||||
|
||||
// Keyboard zoom steps on top of the chosen chat size, not the interface size.
|
||||
act(() => stepAgentSurfaceFontZoom("agent:t1", 2));
|
||||
expect(session.style.getPropertyValue("--markdown-zoom-scale")).toBe("1.125");
|
||||
});
|
||||
|
||||
it("prunes bySurface entries when a tab closes or a task is removed", () => {
|
||||
stepAgentSurfaceFontZoom("tab:tab-a", 4);
|
||||
stepAgentSurfaceFontZoom("tab:tab-b", -2);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { useEffect, type CSSProperties, type RefObject } from "react";
|
||||
import { create } from "zustand";
|
||||
import { editorPrefs } from "@/platform/editorSettings";
|
||||
import { monoFontFamily, uiFontFamily } from "@/platform/fonts";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { registerFontZoomSurface, useEditorShown, useEditorTabId, useToolWindowShown } from "@/workbench/contributions";
|
||||
import { wheelZoomStep } from "@/platform/wheelZoom";
|
||||
import { useAgentSettings } from "./agentSettings";
|
||||
|
||||
const MIN_FONT_ZOOM = -6;
|
||||
const MAX_FONT_ZOOM = 36;
|
||||
@@ -49,7 +51,11 @@ export function resetAllAgentFontZoom(): void {
|
||||
|
||||
function uiFontSizeOf(settings: unknown): number {
|
||||
if (!settings || typeof settings !== "object") return DEFAULT_UI_FONT_SIZE;
|
||||
const a = (settings as { appearance?: { useCustomFont?: unknown; uiFontSize?: unknown } }).appearance;
|
||||
const a = (
|
||||
settings as {
|
||||
appearance?: { useCustomFont?: unknown; uiFontSize?: unknown };
|
||||
}
|
||||
).appearance;
|
||||
return a?.useCustomFont && typeof a.uiFontSize === "number" && a.uiFontSize > 0 ? a.uiFontSize : DEFAULT_UI_FONT_SIZE;
|
||||
}
|
||||
|
||||
@@ -69,7 +75,9 @@ export function useAgentFontZoomSurface(
|
||||
const surfaceKey = agentSurfaceZoomKey(fallbackKey, docked, tabId);
|
||||
const active = enabled && (docked ? toolWindowShown : editorShown);
|
||||
const fontZoom = useAgentFontZoom((s) => s.bySurface[surfaceKey] ?? 0);
|
||||
const baseSize = useProject((s) => uiFontSizeOf(s.settings));
|
||||
const uiBaseSize = useProject((s) => uiFontSizeOf(s.settings));
|
||||
const agents = useAgentSettings();
|
||||
const baseSize = agents.chatUseUiFont ? uiBaseSize : agents.chatFontSize;
|
||||
useEffect(() => {
|
||||
const el = ref.current;
|
||||
if (!active || !el) return;
|
||||
@@ -93,6 +101,23 @@ export function useAgentFontZoomSurface(
|
||||
const zoomStyle = {
|
||||
"--agent-font-zoom": `${fontZoom}px`,
|
||||
"--markdown-zoom-scale": String(zoomScale),
|
||||
...(agents.chatUseUiFont
|
||||
? {}
|
||||
: {
|
||||
"--agent-font-ui": `${uiFontFamily(agents.chatFontFamily, agents.chatFontFallback)}, var(--font-icons)`,
|
||||
"--agent-fs-ui": `calc(${agents.chatFontSize}px + var(--agent-font-zoom, 0px))`,
|
||||
"--agent-fs-small": `calc(${agents.chatFontSize - 1}px + var(--agent-font-zoom, 0px))`,
|
||||
}),
|
||||
...(agents.codeUseDefaultFont
|
||||
? {}
|
||||
: {
|
||||
"--agent-font-code": monoFontFamily(agents.codeFontFamily, agents.codeFontFallback, "var(--font-mono)"),
|
||||
"--agent-fs-code": `calc(${agents.codeFontSize}px + var(--agent-font-zoom, 0px))`,
|
||||
// Fenced code blocks follow the chosen code size; without one they stay chat-derived.
|
||||
"--agent-fs-code-chosen": "var(--agent-fs-code)",
|
||||
// Keep the bundled 13px/22px code ratio at the chosen size.
|
||||
"--lh-code": `${Math.round((agents.codeFontSize * 22) / 13)}px`,
|
||||
}),
|
||||
} as CSSProperties;
|
||||
return { fontZoom, zoomStyle };
|
||||
}
|
||||
@@ -16,6 +16,14 @@ describe("agent chat settings", () => {
|
||||
sendWith: "enter",
|
||||
whileRunning: "queue",
|
||||
newTaskApprovals: "bypass",
|
||||
chatUseUiFont: true,
|
||||
chatFontFamily: "Inter",
|
||||
chatFontFallback: "",
|
||||
chatFontSize: 13,
|
||||
codeUseDefaultFont: true,
|
||||
codeFontFamily: "JetBrains Mono",
|
||||
codeFontFallback: "",
|
||||
codeFontSize: 13,
|
||||
defaults: {},
|
||||
mcpServers: {},
|
||||
skills: {},
|
||||
@@ -31,6 +39,11 @@ describe("agent chat settings", () => {
|
||||
fitWindowWidth: true,
|
||||
});
|
||||
expect(validateSettings({ agents: { fitWindowWidth: "yes" } }).agents.fitWindowWidth).toBe(false);
|
||||
const fonts = validateSettings({
|
||||
agents: { chatUseUiFont: false, chatFontFamily: "Maple Mono NF CN", chatFontSize: 16, codeFontSize: 999 },
|
||||
}).agents;
|
||||
expect(fonts).toMatchObject({ chatUseUiFont: false, chatFontFamily: "Maple Mono NF CN", chatFontSize: 16 });
|
||||
expect(fonts.codeFontSize).toBe(72);
|
||||
});
|
||||
|
||||
it("keeps valid chat choices and per-agent defaults", () => {
|
||||
|
||||
@@ -242,6 +242,14 @@ export const DEFAULT_SETTINGS: ValidSettings = {
|
||||
showCost: false,
|
||||
smoothText: true,
|
||||
fitWindowWidth: false,
|
||||
chatUseUiFont: true,
|
||||
chatFontFamily: "Inter",
|
||||
chatFontFallback: "",
|
||||
chatFontSize: 13,
|
||||
codeUseDefaultFont: true,
|
||||
codeFontFamily: "JetBrains Mono",
|
||||
codeFontFallback: "",
|
||||
codeFontSize: 13,
|
||||
thinking: "auto",
|
||||
toolCalls: "grouped",
|
||||
expandToolOutput: false,
|
||||
@@ -458,6 +466,14 @@ export function validateSettings(raw: Settings | unknown): ValidSettings {
|
||||
showCost: bool(agents.showCost, d.agents.showCost),
|
||||
smoothText: bool(agents.smoothText, d.agents.smoothText),
|
||||
fitWindowWidth: bool(agents.fitWindowWidth, d.agents.fitWindowWidth),
|
||||
chatUseUiFont: bool(agents.chatUseUiFont, d.agents.chatUseUiFont),
|
||||
chatFontFamily: str(agents.chatFontFamily, d.agents.chatFontFamily),
|
||||
chatFontFallback: str(agents.chatFontFallback, d.agents.chatFontFallback),
|
||||
chatFontSize: num(agents.chatFontSize, d.agents.chatFontSize, LIMITS.fontSize, true),
|
||||
codeUseDefaultFont: bool(agents.codeUseDefaultFont, d.agents.codeUseDefaultFont),
|
||||
codeFontFamily: str(agents.codeFontFamily, d.agents.codeFontFamily),
|
||||
codeFontFallback: str(agents.codeFontFallback, d.agents.codeFontFallback),
|
||||
codeFontSize: num(agents.codeFontSize, d.agents.codeFontSize, LIMITS.fontSize, true),
|
||||
thinking: oneOf(agents.thinking, ["auto", "expanded", "collapsed"] as const, d.agents.thinking),
|
||||
toolCalls: oneOf(agents.toolCalls, ["grouped", "each"] as const, d.agents.toolCalls),
|
||||
expandToolOutput: bool(agents.expandToolOutput, d.agents.expandToolOutput),
|
||||
|
||||
@@ -353,6 +353,113 @@ function TerminalFont() {
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Agents › Chat
|
||||
|
||||
function ChatTextFont() {
|
||||
const [useUi, setUseUi] = useSetting<boolean>("agents.chatUseUiFont");
|
||||
const [family, setFamily] = useSetting<string>("agents.chatFontFamily");
|
||||
const [fallback, setFallback] = useSetting<string>("agents.chatFontFallback");
|
||||
const [size, setSize] = useSetting<number>("agents.chatFontSize");
|
||||
const matched = useLabelMatch("Use interface font");
|
||||
return (
|
||||
<>
|
||||
<div className={clsx(styles.inlineRow, matched && styles.matched)}>
|
||||
<Checkbox checked={useUi} onChange={setUseUi} label={<SearchLabel text="Use interface font" />} />
|
||||
<span className={styles.note}>
|
||||
<T>configured in</T>{" "}
|
||||
<PageLink page="appearance">
|
||||
<T>Appearance</T>
|
||||
</PageLink>
|
||||
</span>
|
||||
</div>
|
||||
<div className={terminalStyles.families}>
|
||||
<Row label="Font" stacked disabled={useUi}>
|
||||
<FontPicker value={family} onChange={setFamily} disabled={useUi} label="Chat font" />
|
||||
</Row>
|
||||
<Row label="Fallback font" stacked hint="Used for characters the main font lacks." disabled={useUi}>
|
||||
<FontPicker value={fallback} onChange={setFallback} allowEmpty disabled={useUi} label="Chat fallback font" />
|
||||
</Row>
|
||||
</div>
|
||||
<div className={terminalStyles.metrics}>
|
||||
<Row label="Size" disabled={useUi}>
|
||||
<NumberInput
|
||||
value={size}
|
||||
onChange={setSize}
|
||||
{...L.agentChatFontSize}
|
||||
step={1}
|
||||
unit="px"
|
||||
disabled={useUi}
|
||||
aria-label="Chat font size"
|
||||
/>
|
||||
</Row>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ChatCodeFont() {
|
||||
const [useDefault, setUseDefault] = useSetting<boolean>("agents.codeUseDefaultFont");
|
||||
const [family, setFamily] = useSetting<string>("agents.codeFontFamily");
|
||||
const [fallback, setFallback] = useSetting<string>("agents.codeFontFallback");
|
||||
const [size, setSize] = useSetting<number>("agents.codeFontSize");
|
||||
const matched = useLabelMatch("Use default code font");
|
||||
const monoMatched = useLabelMatch("Show only monospaced fonts");
|
||||
const [monoSetting, setMonoOnly] = useSetting<boolean>("editor.onlyMonospacedFonts");
|
||||
const monoOnly = monoSetting !== false;
|
||||
return (
|
||||
<>
|
||||
<div className={clsx(styles.inlineRow, matched && styles.matched)}>
|
||||
<Checkbox checked={useDefault} onChange={setUseDefault} label={<SearchLabel text="Use default code font" />} />
|
||||
<span className={styles.note}>JetBrains Mono</span>
|
||||
</div>
|
||||
<div className={terminalStyles.families}>
|
||||
<Row label="Font" stacked disabled={useDefault}>
|
||||
<span className={terminalStyles.fontPicker}>
|
||||
<FontPicker
|
||||
value={family}
|
||||
onChange={setFamily}
|
||||
monoOnly={monoOnly}
|
||||
disabled={useDefault}
|
||||
label="Chat code font"
|
||||
/>
|
||||
<span className={monoMatched ? styles.matched : undefined}>
|
||||
<Checkbox
|
||||
checked={monoOnly}
|
||||
onChange={setMonoOnly}
|
||||
disabled={useDefault}
|
||||
label={<SearchLabel text="Show only monospaced fonts" />}
|
||||
/>
|
||||
</span>
|
||||
</span>
|
||||
</Row>
|
||||
<Row label="Fallback font" stacked hint="Used for characters the main font lacks." disabled={useDefault}>
|
||||
<FontPicker
|
||||
value={fallback}
|
||||
onChange={setFallback}
|
||||
allowEmpty
|
||||
disabled={useDefault}
|
||||
label="Chat code fallback font"
|
||||
/>
|
||||
</Row>
|
||||
</div>
|
||||
<div className={terminalStyles.metrics}>
|
||||
<Row label="Size" disabled={useDefault}>
|
||||
<NumberInput
|
||||
value={size}
|
||||
onChange={setSize}
|
||||
{...L.agentCodeFontSize}
|
||||
step={1}
|
||||
unit="px"
|
||||
disabled={useDefault}
|
||||
aria-label="Chat code font size"
|
||||
/>
|
||||
</Row>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Actions on Save
|
||||
|
||||
@@ -783,6 +890,7 @@ export const TOOLS_PAGES: PageSpec[] = [
|
||||
"permission",
|
||||
"bypass",
|
||||
"width",
|
||||
"font",
|
||||
],
|
||||
sections: [
|
||||
{
|
||||
@@ -857,6 +965,28 @@ export const TOOLS_PAGES: PageSpec[] = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Font",
|
||||
options: [
|
||||
{
|
||||
kind: "custom",
|
||||
label: "Use interface font",
|
||||
keywords: ["Chat text", "Font", "Fallback font", "Size"],
|
||||
component: ChatTextFont,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Code Font",
|
||||
options: [
|
||||
{
|
||||
kind: "custom",
|
||||
label: "Use default code font",
|
||||
keywords: ["Code", "Font", "Fallback font", "Size", "Show only monospaced fonts", "monospace"],
|
||||
component: ChatCodeFont,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -2009,6 +2009,15 @@
|
||||
"{names} needs {name} and stops while it is disabled. Disable it anyway?": "{names} needs {name} and stops while it is disabled. Disable it anyway?",
|
||||
"{refactoring} needs {name}. Install it via {method}?": "{refactoring} needs {name}. Install it via {method}?",
|
||||
"Appearance": "Appearance",
|
||||
"Use interface font": "Use interface font",
|
||||
"Use default code font": "Use default code font",
|
||||
"Code Font": "Code Font",
|
||||
"Chat font": "Chat font",
|
||||
"Chat fallback font": "Chat fallback font",
|
||||
"Chat font size": "Chat font size",
|
||||
"Chat code font": "Chat code font",
|
||||
"Chat code fallback font": "Chat code fallback font",
|
||||
"Chat code font size": "Chat code font size",
|
||||
"Behavior": "Behavior",
|
||||
"Sort By": "Sort By",
|
||||
"Type": "Type",
|
||||
|
||||
@@ -3861,7 +3861,9 @@
|
||||
"Use contrast scrollbars": "使用对比度滚动条",
|
||||
"Use custom font": "使用自定义字体",
|
||||
"Use custom font:": "使用自定义字体:",
|
||||
"Use default code font": "使用默认代码字体",
|
||||
"Use editor font": "使用编辑器字体",
|
||||
"Use interface font": "使用界面字体",
|
||||
"Use lighter color in the dark theme and darker color in the light theme as a background": "在深色主题中使用较浅的颜色、在浅色主题中使用较深的颜色作为背景",
|
||||
"Use original line's indent for wrapped parts": "换行部分使用原始行的缩进",
|
||||
"Use pretty formatting": "使用友好格式",
|
||||
@@ -7433,6 +7435,13 @@
|
||||
"Weekly Opus limit": "每周 Opus 限额",
|
||||
"Weekly Sonnet limit": "每周 Sonnet 限额",
|
||||
"Chat": "聊天",
|
||||
"Code Font": "代码字体",
|
||||
"Chat font": "聊天字体",
|
||||
"Chat fallback font": "聊天备用字体",
|
||||
"Chat font size": "聊天字体大小",
|
||||
"Chat code font": "聊天代码字体",
|
||||
"Chat code fallback font": "聊天代码备用字体",
|
||||
"Chat code font size": "聊天代码字体大小",
|
||||
"Shown in the Task Header": "在任务标题栏中显示",
|
||||
"Context window usage": "上下文窗口用量",
|
||||
"Usage limits": "用量限额",
|
||||
|
||||
@@ -279,6 +279,8 @@ export const WORKFLOW_LIMITS = {
|
||||
terminalFontSize: { min: 6, max: 72 },
|
||||
terminalLineHeight: { min: 0.5, max: 3 },
|
||||
terminalColumnWidth: { min: 0.5, max: 2 },
|
||||
agentChatFontSize: { min: 6, max: 72 },
|
||||
agentCodeFontSize: { min: 6, max: 72 },
|
||||
} as const;
|
||||
|
||||
export const DEFAULT_EXTERNAL_TOOL: ExternalToolValid = {
|
||||
|
||||
Reference in new issue
Заблокувати користувача