fix(run): expand multiline configuration fields in place (#5267)

Multiline run configuration fields now keep the Expand button inside the field. The larger editor opens next to the field so the configuration stays in view. It can be resized, scrolls long arguments horizontally, and applies edits through OK or Ctrl/⌘+Enter.
This commit is contained in:
l0ng-ai
2026-11-23 09:16:39 +08:00
committed by GitHub
parent 03a19d4284
commit 43eeb080be
3 changed files with 153 additions and 44 deletions
+63
View File
@@ -2,6 +2,69 @@ import type { Page } from "@playwright/test";
import type { BeforeLaunchTask } from "../src/bindings";
import { expect, test } from "./fixtures";
test("expands VM options beside the field and returns edited text to the configuration", async ({
workbench: page,
}) => {
const original = "-Xmx512m\n-Ddemo.endpoint=https://example.test/" + "long-segment/".repeat(12);
await page.evaluate(async (vmOptions) => {
const path = "/src/features/run/store.ts";
const { useRun } = await import(/* @vite-ignore */ path);
useRun.setState({
configs: [
{
id: "layout:jvm",
name: "Catalog service",
kind: "application",
command: "java",
args: ["example.Catalog"],
params: { mainClass: "example.Catalog", vmOptions },
env: {},
cwd: null,
detected: false,
isTest: false,
debugAdapter: "java-debug",
},
],
editTarget: "layout:jvm",
loaded: true,
editorOpen: true,
});
}, original);
const config = page.getByRole("dialog", { name: "Run/Debug Configurations", exact: true });
const field = config.getByRole("textbox", { name: "VM options", exact: true });
const expanded = page.getByRole("dialog", { name: "VM options", exact: true });
const editor = expanded.getByRole("textbox", { name: "VM options", exact: true });
for (const width of [1100, 560]) {
await page.setViewportSize({ width, height: 760 });
await field.scrollIntoViewIfNeeded();
await field.press("Shift+Enter");
await expect(editor).toBeFocused();
await expect
.poll(async () => {
const source = (await field.boundingBox())!;
const popup = (await expanded.boundingBox())!;
const gap = Math.min(Math.abs(popup.y - source.y - source.height), Math.abs(source.y - popup.y - popup.height));
return popup.x >= 0 && popup.x + popup.width <= width && gap <= 6;
})
.toBe(true);
await expect.poll(() => editor.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeGreaterThan(0);
await editor.fill("-Xmx1g");
await editor.press("Escape");
await expect(expanded).toBeHidden();
await expect(field).toBeFocused();
await expect(field).toHaveValue(original);
}
const expand = config.getByRole("button", { name: "Expand (⇧⏎)", exact: true });
await expand.click();
await expect(editor).toBeFocused();
await editor.fill(original + "\n-Ddemo.mode=local");
await editor.press("Control+Enter");
await expect(expanded).toBeHidden();
await expect(field).toHaveValue(original + "\n-Ddemo.mode=local");
});
async function openConfigurations(page: Page, target?: string, beforeLaunch?: BeforeLaunchTask[]) {
await page.evaluate(
async ({ target, beforeLaunch }) => {
+64 -34
View File
@@ -1,7 +1,8 @@
import { useState } from "react";
import { useRef, useState, type RefObject } from "react";
import clsx from "clsx";
import { useTx } from "@/platform/i18n";
import { Dialog, IconButton } from "@/ui";
import { isImeKey } from "@/platform/ime";
import { Button, IconButton, Popup } from "@/ui";
import styles from "./Run.module.css";
/**
@@ -25,9 +26,10 @@ export function ExpandableTextarea({
onChange: (value: string) => void;
}) {
const tx = useTx();
const fieldRef = useRef<HTMLDivElement>(null);
const [expanded, setExpanded] = useState(false);
return (
<div className={styles.textareaWithButton}>
<div ref={fieldRef} className={styles.textareaWithButton}>
<textarea
className={clsx(styles.textarea, invalid && styles.textareaInvalid)}
aria-label={tx(label)}
@@ -43,58 +45,86 @@ export function ExpandableTextarea({
}
}}
/>
<IconButton icon="expand-all" size="small" iconSize={14} title="Expand (⇧⏎)" onClick={() => setExpanded(true)} />
<IconButton
icon="expand-all"
size="small"
iconSize={14}
title="Expand (⇧⏎)"
aria-haspopup="dialog"
aria-expanded={expanded}
onClick={() => setExpanded(!expanded)}
/>
{expanded && (
<ExpandedTextDialog label={label} value={value} onOk={onChange} onClose={() => setExpanded(false)} />
<ExpandedTextPopup
anchor={fieldRef}
label={tx(label)}
value={value}
onOk={onChange}
onClose={() => setExpanded(false)}
/>
)}
</div>
);
}
function ExpandedTextDialog({
function ExpandedTextPopup({
anchor,
label,
value,
onOk,
onClose,
}: {
anchor: RefObject<HTMLDivElement | null>;
label: string;
value: string;
onOk: (value: string) => void;
onClose: () => void;
}) {
const tx = useTx();
const [text, setText] = useState(value);
const apply = () => {
if (text !== value) onOk(text);
onClose();
};
return (
<Dialog
<Popup
open
title={tx(label)}
anchor={anchor}
aria-label={label}
className={styles.expandedEditor}
onClose={onClose}
width={720}
trapFocus
matchWidth
closeOnDeactivate={false}
resizable="both"
minWidth={360}
minHeight={220}
buttons={[
{
label: "OK",
role: "default",
onClick: () => {
if (text !== value) onOk(text);
onClose();
},
},
{ label: "Cancel", role: "cancel" },
]}
minWidth={240}
minHeight={160}
>
<textarea
className={clsx(styles.textarea, styles.expandedTextarea)}
aria-label={tx(label)}
spellCheck={false}
wrap="off"
rows={14}
value={text}
autoFocus
onChange={(e) => setText(e.target.value)}
/>
</Dialog>
<div
className={styles.expandedEditorBody}
onKeyDown={(e) => {
if (e.key !== "Enter" || !(e.ctrlKey || e.metaKey) || e.altKey || e.shiftKey || isImeKey(e.nativeEvent))
return;
e.preventDefault();
e.stopPropagation();
apply();
}}
>
<textarea
className={clsx(styles.textarea, styles.expandedTextarea)}
aria-label={label}
spellCheck={false}
wrap="off"
value={text}
data-autofocus
onChange={(e) => setText(e.target.value)}
/>
<div className={styles.expandedEditorActions}>
<Button onClick={onClose}>Cancel</Button>
<Button variant="primary" onClick={apply}>
OK
</Button>
</div>
</div>
</Popup>
);
}
+26 -10
View File
@@ -922,28 +922,44 @@
outline: none;
}
.textareaWithButton {
display: flex;
align-items: flex-start;
gap: var(--space-1-5);
position: relative;
min-width: 0;
}
.textareaWithButton > textarea {
flex: 1;
min-width: 0;
display: block;
width: 100%;
padding-inline-end: calc(var(--space-3) + var(--space-4));
}
.textareaWithButton > button {
flex-shrink: 0;
position: absolute;
inset-block-start: var(--space-1);
inset-inline-end: var(--space-1);
}
.expandedEditor {
width: 512px;
height: 272px;
}
.expandedEditorBody {
display: flex;
flex-direction: column;
height: 100%;
padding: var(--space-2);
gap: var(--space-2);
}
/* One visual line per line of text: a long argument scrolls instead of wrapping. */
.expandedTextarea {
width: 100%;
height: 100%;
min-height: 160px;
box-sizing: border-box;
flex: 1;
min-height: 0;
resize: none;
white-space: pre;
overflow: auto;
}
.expandedEditorActions {
display: flex;
justify-content: flex-end;
flex: none;
gap: var(--space-2);
}
.textarea:focus {
box-shadow: inset 0 0 0 1px var(--focus-ring);
}