fix(run): keep console soft wrap across run tabs (#6331)

The Run/Services and Debug console toolbars kept soft wrap in component state, so switching run tabs reset it to the Settings default. The toolbar toggle now writes Settings > Console > Use soft wraps in console (console.softWrap) and every console reads it, so one toggle applies to all consoles and survives a restart. The e2e settings-write stub moves into the shared fixtures.

Co-authored-by: Greenker <[email protected]>
Цей коміт міститься в:
Mollo-i authored and GitHub committed 2026-11-27 14:19:24 +08:00
1 джерело 944b57dead
коміт dfbd13e2af
7 files changed
+91 -40

No files matched your search

+2 -27
Переглянути файл
@@ -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<string, unknown>;
const path = key.split(".");
let node = next;
for (const seg of path.slice(0, -1)) {
node[seg] ??= {};
node = node[seg] as Record<string, unknown>;
}
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 }) => {
+27
Переглянути файл
@@ -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<string, unknown>;
const path = key.split(".");
let node = next;
for (const seg of path.slice(0, -1)) {
node[seg] ??= {};
node = node[seg] as Record<string, unknown>;
}
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<Record<string, unknown>[]> {
return page.evaluate((cmd) => window.__ipc.calls.filter((c) => c.cmd === cmd).map((c) => c.args), cmd);
+2 -1
Переглянути файл
@@ -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<RunConfig> = {},
) {
await stubDesktop(page);
await stubSettingsWrites(page);
await page.evaluate(
async ({ output, exit, runId, overrides }) => {
const config = {
+9 -6
Переглянути файл
@@ -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<boolean | null>(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())}
/>
<IconButton icon="scroll-to-end" title="Scroll to End" pressed={follow} onClick={() => setFollow((v) => !v)} />
<IconButton icon="soft-wrap" title="Soft-Wrap" pressed={softWrap} onClick={() => setWrapOverride(!softWrap)} />
<IconButton
icon="soft-wrap"
title="Soft-Wrap"
pressed={softWrap}
onClick={() => void setConsoleSoftWrap(!softWrap)}
/>
<IconButton icon="trash" title="Clear Console" onClick={() => clearConsole(session.id)} />
</div>
<div className={styles.console}>
+5 -6
Переглянути файл
@@ -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<boolean | null>(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<string | null>(null);
const [findOpen, setFindOpen] = useState(false);
const body = useRef<HTMLDivElement>(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
+38
Переглянути файл
@@ -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<string, unknown>;
const path = key.split(".");
let node = settings;
for (const part of path.slice(0, -1)) node = (node[part] ??= {}) as Record<string, unknown>;
node[path.at(-1)!] = JSON.parse(value);
return { status: "ok" as const, data: settings };
}),
}));
vi.mock("@/platform/ipc", async (orig) => {
const real = await orig<typeof import("@/platform/ipc")>();
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);
});
});
+8
Переглянути файл
@@ -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<void> {
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<T>(select: (s: WorkflowSettings) => T): T {
return useProject((p) => {