Compare commits

...
Author SHA1 Message Date
l0ng-ai 2f1f6ed485 fix(run): anchor console fold controls in the gutter 2026-11-22 18:28:05 +08:00
3 changed files with 94 additions and 14 deletions

No files matched your search

+67
View File
@@ -76,6 +76,73 @@ test("⌃R runs the selected configuration and shows its output and exit", async
expect(started).toMatchObject({ config: { id: "npm:dev", command: "npm", args: ["run", "dev"] } });
});
test("expanded console folds stay reachable at the start of their rows", async ({ workbench: page }) => {
const heading = "Reconciling orders for the overnight settlement and inventory reporting pipeline";
await stubRun(
page,
[
{
kind: "stdout",
text: [
"TRACE Reused inventory connection",
"TRACE Loaded warehouse configuration",
heading,
"TRACE Checked warehouse audit result",
"TRACE Updated inventory snapshot",
"Processed 24 orders",
"",
].join("\n"),
},
],
null,
);
await page.evaluate(async () => {
const projectModule = "/src/platform/project.ts";
const layoutModule = "/src/workbench/toolwindows/store.ts";
const { useProject } = await import(/* @vite-ignore */ projectModule);
const { moveToolWindow, setToolWindowSize } = await import(/* @vite-ignore */ layoutModule);
const { settings } = useProject.getState();
useProject.setState({
settings: { ...settings, console: { ...settings?.console, foldPatterns: ["TRACE "] } },
});
moveToolWindow("run", "right");
setToolWindowSize("right", 320);
});
await page.keyboard.press("Control+r");
const log = page.getByRole("region", { name: "Run", exact: true }).getByRole("log");
const expand = log.getByTitle("Expand folded lines", { exact: true });
const collapse = log.getByRole("button", { name: "Collapse folded lines", exact: true });
await expect(expand).toHaveCount(2);
await expand.first().click();
await expect(log.getByText("TRACE Reused inventory connection", { exact: true })).toBeVisible();
await expect(collapse).toHaveCount(1);
await collapse.press("Space");
await expect(expand).toHaveCount(2);
await expand.first().press("Enter");
await expect(collapse).toBeFocused();
await expand.last().click();
await expect(collapse).toHaveCount(2);
for (const scrollLeft of [0, 120]) {
await log.evaluate((element, x) => (element.scrollLeft = x), scrollLeft);
expect(await log.evaluate((element) => element.scrollLeft)).toBe(scrollLeft);
for (const control of await collapse.all()) {
const aligned = await control.evaluate((button) => {
const log = button.closest('[role="log"]')!.getBoundingClientRect();
const row = button.closest("[data-index]")!.getBoundingClientRect();
const box = button.getBoundingClientRect();
return Math.abs(box.left - log.left) <= 1 && box.top >= row.top && box.bottom <= row.bottom + 1;
});
expect(aligned).toBe(true);
}
}
await collapse.first().click();
await collapse.first().click();
await expect(expand).toHaveCount(2);
expect(await ipcCalls(page, "run_stdin")).toEqual([]);
});
test("⌘F2 stops a running process", async ({ workbench: page }) => {
await stubRun(page, [{ kind: "stdout", text: "Watching for changes…\n" }], null);
await page.keyboard.press("Control+r");
+15 -6
View File
@@ -143,7 +143,10 @@ export function foldRows(
const fold: Fold = { start: i, count: j - i, id: lines[i]!.id, expanded: expanded.has(lines[i]!.id) };
const prev = rows[rows.length - 1];
if (prev?.kind === "line") prev.fold = fold;
else if (!fold.expanded) rows.push({ kind: "fold", fold });
else if (fold.expanded) {
rows.push({ kind: "line", index: i, fold });
i++;
} else rows.push({ kind: "fold", fold });
if (fold.expanded) for (; i < j; i++) rows.push({ kind: "line", index: i });
i = j;
continue;
@@ -230,7 +233,7 @@ export function ConsoleView({
// Pending input continues the open line (a prompt), or starts a row of its own.
const lastRow = folded[folded.length - 1];
const inputInline =
!!input && !!model.openLine && lastRow?.kind === "line" && !lastRow.fold && lines[lastRow.index] === model.openLine;
!!input && !!model.openLine && lastRow?.kind === "line" && lines[lastRow.index] === model.openLine;
const inputRow = !!input && !inputInline;
const [widest] = useState(() => new WidestColumns());
// eslint-disable-next-line react-hooks/exhaustive-deps -- `version` marks in-place appends to `lines`
@@ -255,7 +258,7 @@ export function ConsoleView({
getItemKey: (i) => {
const r = rows[i];
if (!r) return "input";
return r.kind === "fold" ? `f${r.fold.id}` : (lines[r.index]?.id ?? i);
return r.kind === "fold" ? r.fold.id : (lines[r.index]?.id ?? i);
},
});
@@ -486,7 +489,7 @@ export function ConsoleView({
return;
}
if (copySelectionOnKeyDown(e, selectedOutput)) return;
if (!input) return;
if (!input || e.target instanceof HTMLButtonElement) return;
if (e.key === "d" && e.ctrlKey && !e.metaKey && !e.altKey) {
e.preventDefault();
input.onEof();
@@ -523,19 +526,24 @@ export function ConsoleView({
const foldButton = (fold: Fold, attached: boolean) =>
fold.expanded ? (
<button
key={fold.id}
type="button"
className={styles.foldToggle}
style={{ height: rowHeight }}
title={tx("Collapse folded lines")}
aria-label={tx("Collapse folded lines")}
aria-expanded={true}
onClick={() => toggleFold(fold.id)}
>
<Icon name="chevron-up" size={10} />
<Icon name="chevron-down" size={10} />
</button>
) : (
<button
key={fold.id}
type="button"
className={styles.fold}
title={tx("Expand folded lines")}
aria-expanded={false}
onClick={() => toggleFold(fold.id)}
>
{`${attached ? " " : ""}${fold.count === 1 ? tx`<${fold.count} internal line>` : tx`<${fold.count} internal lines>`}`}
@@ -651,6 +659,7 @@ export function ConsoleView({
className={clsx(styles.line, styles[line.kind])}
style={{ ...rowStyle(item.start), color, background: ruled?.line?.bg }}
>
{row.fold?.expanded && foldButton(row.fold, false)}
<Line
line={line}
marks={marksByLine.get(row.index)}
@@ -658,7 +667,7 @@ export function ConsoleView({
length={line.text.length}
cwd={cwd}
/>
{row.fold && foldButton(row.fold, true)}
{row.fold && !row.fold.expanded && foldButton(row.fold, true)}
{inputInline && item.index === rows.length - 1 && pendingInput}
{"\n"}
</div>
+12 -8
View File
@@ -212,7 +212,7 @@
top: 0;
left: 0;
min-width: 100%;
padding: 0 12px;
padding: 0 var(--space-3);
line-height: inherit;
white-space: pre;
tab-size: 4;
@@ -1118,15 +1118,19 @@
color: var(--fg);
}
.foldToggle {
display: inline-flex;
align-items: center;
margin-left: 6px;
padding: 0 2px;
position: sticky;
inset-inline-start: 0;
z-index: 1;
display: inline-grid;
place-items: center;
width: var(--space-3);
margin-inline-start: calc(-1 * var(--space-3));
padding: 0;
border: none;
border-radius: 3px;
background: none;
border-radius: var(--radius-small);
background: var(--bg-app);
color: var(--fg-faint);
vertical-align: middle;
vertical-align: top;
cursor: pointer;
}
.foldToggle:hover {