diff --git a/e2e/commitDoubleClick.spec.ts b/e2e/commitDoubleClick.spec.ts index 0c68e5d1e6..109f01b1b3 100644 --- a/e2e/commitDoubleClick.spec.ts +++ b/e2e/commitDoubleClick.spec.ts @@ -3,7 +3,7 @@ * menu, the modal Commit dialog and the non-modal Commit window defaults. Git is stubbed at the IPC layer. */ import type { Locator, Page } from "@playwright/test"; -import { expect, openFromTree, stubDesktop, test } from "./fixtures"; +import { expect, openFromTree, stubDesktop, stubSettingsWrites, test } from "./fixtures"; const ROOT = "/dev/acme-api"; const FILE = "build.gradle.kts"; @@ -43,33 +43,8 @@ async function stubRepository(page: Page) { } /** - * Settings writes land in the project store the way the backend answers `settings_set`: the dotted - * key is set, `null` removes it, and the store takes the returned settings. + * Sets a commit setting in the store directly, before the window that reads it opens. */ -async function stubSettingsWrites(page: Page) { - await page.evaluate(async () => { - const storeModule = "/src/platform/project.ts"; - const { useProject } = await import(/* @vite-ignore */ storeModule); - window.__ipc.handlers.settings_set = (args) => { - const { key, value } = args as { key: string; value: string }; - const next = structuredClone(useProject.getState().settings ?? {}) as Record; - const path = key.split("."); - let node = next; - for (const seg of path.slice(0, -1)) { - node[seg] ??= {}; - node = node[seg] as Record; - } - const last = path[path.length - 1]!; - const parsed: unknown = JSON.parse(value); - if (parsed === null) delete node[last]; - else node[last] = parsed; - useProject.setState({ settings: next as never }); - return next; - }; - }); -} - -/** Sets a commit setting in the store directly, before the window that reads it opens. */ async function setCommitSetting(page: Page, key: "nonModal" | "doubleClickOpensDiff", value: boolean | null) { await page.evaluate( async ({ key, value }) => { diff --git a/e2e/fixtures.ts b/e2e/fixtures.ts index f0ed8f71bf..25c8082556 100644 --- a/e2e/fixtures.ts +++ b/e2e/fixtures.ts @@ -118,6 +118,33 @@ export async function stubDesktop(page: Page) { }); } +/** + * Makes `settings_set` answer like the backend: the dotted key lands in the project store (and + * `null` removes it), so toolbar toggles that write a setting behave as they do in the app. + */ +export async function stubSettingsWrites(page: Page) { + await page.evaluate(async () => { + const storeModule = "/src/platform/project.ts"; + const { useProject } = await import(/* @vite-ignore */ storeModule); + window.__ipc.handlers.settings_set = (args) => { + const { key, value } = args as { key: string; value: string }; + const next = structuredClone(useProject.getState().settings ?? {}) as Record; + const path = key.split("."); + let node = next; + for (const seg of path.slice(0, -1)) { + node[seg] ??= {}; + node = node[seg] as Record; + } + const last = path[path.length - 1]!; + const parsed: unknown = JSON.parse(value); + if (parsed === null) delete node[last]; + else node[last] = parsed; + useProject.setState({ settings: next as never }); + return next; + }; + }); +} + /** The commands the page has invoked so far under `stubDesktop`, by name. */ export async function ipcCalls(page: Page, cmd: string): Promise[]> { return page.evaluate((cmd) => window.__ipc.calls.filter((c) => c.cmd === cmd).map((c) => c.args), cmd); diff --git a/e2e/run.spec.ts b/e2e/run.spec.ts index 5ddd88848d..746ffb62dd 100644 --- a/e2e/run.spec.ts +++ b/e2e/run.spec.ts @@ -4,7 +4,7 @@ */ import type { Page } from "@playwright/test"; import type { RunConfig } from "../src/bindings"; -import { expect, ipcCalls, stubDesktop, test } from "./fixtures"; +import { expect, ipcCalls, stubDesktop, stubSettingsWrites, test } from "./fixtures"; const RUN_ID = 7; @@ -16,6 +16,7 @@ async function stubRun( overrides: Partial = {}, ) { await stubDesktop(page); + await stubSettingsWrites(page); await page.evaluate( async ({ output, exit, runId, overrides }) => { const config = { diff --git a/src/features/debugger/ui/DebugConsole.tsx b/src/features/debugger/ui/DebugConsole.tsx index 819f5ca3fe..3537cf1fe1 100644 --- a/src/features/debugger/ui/DebugConsole.tsx +++ b/src/features/debugger/ui/DebugConsole.tsx @@ -14,7 +14,7 @@ import { copySelectionOnKeyDown, copyText } from "@/ui/selectableText"; import { EmptyState, IconButton, showContextMenu, T, type MenuItem } from "@/ui"; import { formatBinding, hasPrimaryModifier, hostBinding, registerKeyClaim } from "@/platform/keymap"; import { tx } from "@/platform/i18n"; -import { useWorkflowSettings } from "@/platform/workflowSettings"; +import { setConsoleSoftWrap, useWorkflowSettings } from "@/platform/workflowSettings"; import { useConsoleFont } from "@/platform/consoleFont"; import { spanStyle } from "@/ui/ansi"; import { logLineColor } from "@/ui/logColors"; @@ -151,12 +151,10 @@ export function DebugConsole({ session, interactive = true }: { session: DebugSe 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); + // Settings › Console › Use soft wraps is shared by every console; the toolbar toggle writes it. + const softWrap = useWorkflowSettings((s) => s.console.softWrap); const logColors = useWorkflowSettings((s) => s.console.logColors); const consoleRules = compileConsoleRules(useConsoleRules((s) => s.providers)); - const [wrapOverride, setWrapOverride] = useState(null); - const softWrap = wrapOverride ?? defaultWrap; const [widest] = useState(() => new WidestColumns()); const columns = useMemo(() => widest.measure(lines ?? []), [widest, lines]); const programmatic = useRef(false); @@ -440,7 +438,12 @@ export function DebugConsole({ session, interactive = true }: { session: DebugSe onClick={() => (findOpen ? closeFind() : openFind())} /> setFollow((v) => !v)} /> - setWrapOverride(!softWrap)} /> + void setConsoleSoftWrap(!softWrap)} + /> clearConsole(session.id)} />
diff --git a/src/features/run/RunView.tsx b/src/features/run/RunView.tsx index c660391ddc..1dd0d65598 100644 --- a/src/features/run/RunView.tsx +++ b/src/features/run/RunView.tsx @@ -3,7 +3,7 @@ import clsx from "clsx"; import type { GroupImperativeHandle, Layout } from "react-resizable-panels"; import type { RunConfig } from "@/platform/ipc"; import type { RunTargetValid } from "@/platform/remoteSettings"; -import { useAgentRunSettings, useWorkflowSettings } from "@/platform/workflowSettings"; +import { setConsoleSoftWrap, useAgentRunSettings, useWorkflowSettings } from "@/platform/workflowSettings"; import { EmptyState, Icon, @@ -101,10 +101,9 @@ export function SessionPanel({ const version = useRun((s) => s.versions[session.id] ?? 0); const rt = runtime(session.id); const [follow, setFollow] = useState(true); - // Settings › Console › Use soft wraps is the default; the toolbar toggle overrides it for this tab. - const defaultWrap = useWorkflowSettings((s) => s.console.softWrap); - const [wrapOverride, setWrapOverride] = useState(null); - const softWrap = wrapOverride ?? defaultWrap; + // Settings › Console › Use soft wraps is shared by every run tab, so the toolbar toggle + // writes it instead of keeping a per-tab override that a tab switch would drop. + const softWrap = useWorkflowSettings((s) => s.console.softWrap); const [selectedTest, setSelectedTest] = useState(null); const [findOpen, setFindOpen] = useState(false); const body = useRef(null); @@ -186,7 +185,7 @@ export function SessionPanel({ const overflowConsoleToggles = showLifecycle && compactToolbar && !rt.terminal; const consoleToggles = [ { label: "Scroll to End", icon: "scroll-to-end", checked: follow, run: () => setFollow((v) => !v) }, - { label: "Soft-Wrap", icon: "soft-wrap", checked: softWrap, run: () => setWrapOverride(!softWrap) }, + { label: "Soft-Wrap", icon: "soft-wrap", checked: softWrap, run: () => void setConsoleSoftWrap(!softWrap) }, ]; // IDEA's console toolbar names Previous / Next Occurrence after what they step through here. const stackTraceActions = rt.tests diff --git a/src/platform/consoleSoftWrap.test.ts b/src/platform/consoleSoftWrap.test.ts new file mode 100644 index 0000000000..734eacadb0 --- /dev/null +++ b/src/platform/consoleSoftWrap.test.ts @@ -0,0 +1,38 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; + +/** Writes the dotted key into the current settings, as the host does. */ +const ipc = vi.hoisted(() => ({ + settingsSet: vi.fn(async (_scope: string, key: string, value: string) => { + const { useProject } = await import("@/platform/project"); + const settings = structuredClone(useProject.getState().settings ?? {}) as Record; + const path = key.split("."); + let node = settings; + for (const part of path.slice(0, -1)) node = (node[part] ??= {}) as Record; + node[path.at(-1)!] = JSON.parse(value); + return { status: "ok" as const, data: settings }; + }), +})); +vi.mock("@/platform/ipc", async (orig) => { + const real = await orig(); + return { ...real, isTauri: () => true, commands: { ...real.commands, ...ipc } }; +}); + +const { setConsoleSoftWrap, workflowSettings } = await import("./workflowSettings"); +const { useProject } = await import("./project"); + +afterEach(() => { + useProject.setState({ settings: null }); + vi.clearAllMocks(); +}); + +describe("setConsoleSoftWrap", () => { + it("writes the global console setting so every run tab follows it", async () => { + await setConsoleSoftWrap(true); + expect(ipc.settingsSet).toHaveBeenCalledWith("global", "console.softWrap", "true"); + expect(workflowSettings().console.softWrap).toBe(true); + + await setConsoleSoftWrap(false); + expect(ipc.settingsSet).toHaveBeenLastCalledWith("global", "console.softWrap", "false"); + expect(workflowSettings().console.softWrap).toBe(false); + }); +}); diff --git a/src/platform/workflowSettings.ts b/src/platform/workflowSettings.ts index babb1c9ef8..8bfbf20106 100644 --- a/src/platform/workflowSettings.ts +++ b/src/platform/workflowSettings.ts @@ -11,6 +11,7 @@ import type { HotSwapPolicy, StashDiffTarget, } from "@/bindings"; +import { call, commands } from "./ipc"; import { useProject } from "./project"; import { DEFAULT_REMOTE, validateRemote, type RemoteSettings } from "./remoteSettings"; @@ -779,6 +780,13 @@ export function workflowSettings(): WorkflowSettings { return cached; } +/** Settings › Console › Use soft wraps in console, written by the consoles' toolbar toggle. */ +export async function setConsoleSoftWrap(softWrap: boolean): Promise { + useProject.setState({ + settings: await call(commands.settingsSet("global", "console.softWrap", JSON.stringify(softWrap))), + }); +} + /** React hook over one section, e.g. `useWorkflowSettings((s) => s.terminal)`. */ export function useWorkflowSettings(select: (s: WorkflowSettings) => T): T { return useProject((p) => {