mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-22 09:39:27 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e7492c194 |
No files matched your search
@@ -33,6 +33,7 @@ import {
|
||||
} from "@/ui";
|
||||
import { useContributions, type RunConfigTypeContribution } from "@/workbench/contributions";
|
||||
import { TASK_LABELS, taskLabel, type BeforeLaunchKind } from "./beforeLaunch";
|
||||
import { ExpandableTextarea } from "./ExpandableTextarea";
|
||||
import {
|
||||
commandLine,
|
||||
compoundCycle,
|
||||
@@ -817,7 +818,6 @@ function TypeField({
|
||||
invalid: boolean;
|
||||
onChange: (value: string) => void;
|
||||
}) {
|
||||
const tx = useTx();
|
||||
const root = useProject((s) => s.project?.root ?? null);
|
||||
const listId = `run-field-${field.key}`;
|
||||
const [loaded, setLoaded] = useState<ReadonlyArray<{ value: string; label: string; detail?: string }>>([]);
|
||||
@@ -848,14 +848,13 @@ function TypeField({
|
||||
return <Checkbox checked={value === "true"} onChange={(on) => onChange(on ? "true" : "")} label={field.label} />;
|
||||
if (field.control === "textarea")
|
||||
return (
|
||||
<textarea
|
||||
className={clsx(styles.textarea, invalid && styles.textareaInvalid)}
|
||||
aria-label={tx(field.label)}
|
||||
spellCheck={false}
|
||||
<ExpandableTextarea
|
||||
label={field.label}
|
||||
value={value}
|
||||
placeholder={tx(field.placeholder)}
|
||||
rows={field.rows ?? 4}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
placeholder={field.placeholder}
|
||||
rows={field.rows}
|
||||
invalid={invalid}
|
||||
onChange={onChange}
|
||||
/>
|
||||
);
|
||||
const suggestions = field.suggestions?.(all, params) ?? [];
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
||||
import { ExpandableTextarea } from "./ExpandableTextarea";
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
const LONG = "-Ddemo.endpoint=https://example.com/demo/environments/local/feature-flags/configuration/versions/current";
|
||||
const VALUE = `-Xmx512m\n${LONG}\n-Ddemo.mode=local`;
|
||||
|
||||
function editors() {
|
||||
return screen.getAllByRole("textbox", { name: "VM options" }) as HTMLTextAreaElement[];
|
||||
}
|
||||
|
||||
it("edits in an expanded editor that keeps each line on one visual line", () => {
|
||||
const onChange = vi.fn();
|
||||
render(<ExpandableTextarea label="VM options" value={VALUE} onChange={onChange} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Expand (⇧⏎)" }));
|
||||
const expanded = editors()[1]!;
|
||||
expect(expanded.value).toBe(VALUE);
|
||||
expect(expanded.getAttribute("wrap")).toBe("off");
|
||||
fireEvent.change(expanded, { target: { value: `${VALUE}\n-Dextra=1` } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "OK" }));
|
||||
expect(onChange).toHaveBeenCalledWith(`${VALUE}\n-Dextra=1`);
|
||||
expect(editors()).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("leaves the value alone on Cancel or OK without edits, and opens with Shift+Enter", () => {
|
||||
const onChange = vi.fn();
|
||||
render(<ExpandableTextarea label="VM options" value={VALUE} onChange={onChange} />);
|
||||
fireEvent.keyDown(editors()[0]!, { key: "Enter", shiftKey: true });
|
||||
fireEvent.change(editors()[1]!, { target: { value: "-Xmx1g" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
expect(editors()).toHaveLength(1);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Expand (⇧⏎)" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "OK" }));
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -0,0 +1,100 @@
|
||||
import { useState } from "react";
|
||||
import clsx from "clsx";
|
||||
import { useTx } from "@/platform/i18n";
|
||||
import { Dialog, IconButton } from "@/ui";
|
||||
import styles from "./Run.module.css";
|
||||
|
||||
/**
|
||||
* A run configuration's multi-line field (VM options, say) with an Expand button (⇧⏎) that
|
||||
* edits it in a larger editor where each line stays on one visual line and scrolls sideways,
|
||||
* so one long argument isn't mistaken for several.
|
||||
*/
|
||||
export function ExpandableTextarea({
|
||||
label,
|
||||
value,
|
||||
placeholder,
|
||||
rows,
|
||||
invalid,
|
||||
onChange,
|
||||
}: {
|
||||
label: string;
|
||||
value: string;
|
||||
placeholder?: string;
|
||||
rows?: number;
|
||||
invalid?: boolean;
|
||||
onChange: (value: string) => void;
|
||||
}) {
|
||||
const tx = useTx();
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
return (
|
||||
<div className={styles.textareaWithButton}>
|
||||
<textarea
|
||||
className={clsx(styles.textarea, invalid && styles.textareaInvalid)}
|
||||
aria-label={tx(label)}
|
||||
spellCheck={false}
|
||||
value={value}
|
||||
placeholder={tx(placeholder)}
|
||||
rows={rows ?? 4}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" && e.shiftKey && !e.altKey && !e.metaKey && !e.ctrlKey) {
|
||||
e.preventDefault();
|
||||
setExpanded(true);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<IconButton icon="expand-all" size="small" iconSize={14} title="Expand (⇧⏎)" onClick={() => setExpanded(true)} />
|
||||
{expanded && (
|
||||
<ExpandedTextDialog label={label} value={value} onOk={onChange} onClose={() => setExpanded(false)} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ExpandedTextDialog({
|
||||
label,
|
||||
value,
|
||||
onOk,
|
||||
onClose,
|
||||
}: {
|
||||
label: string;
|
||||
value: string;
|
||||
onOk: (value: string) => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const tx = useTx();
|
||||
const [text, setText] = useState(value);
|
||||
return (
|
||||
<Dialog
|
||||
open
|
||||
title={tx(label)}
|
||||
onClose={onClose}
|
||||
width={720}
|
||||
resizable="both"
|
||||
minWidth={360}
|
||||
minHeight={220}
|
||||
buttons={[
|
||||
{
|
||||
label: "OK",
|
||||
role: "default",
|
||||
onClick: () => {
|
||||
if (text !== value) onOk(text);
|
||||
onClose();
|
||||
},
|
||||
},
|
||||
{ label: "Cancel", role: "cancel" },
|
||||
]}
|
||||
>
|
||||
<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>
|
||||
);
|
||||
}
|
||||
@@ -848,6 +848,29 @@
|
||||
font-size: var(--fs-ui);
|
||||
outline: none;
|
||||
}
|
||||
.textareaWithButton {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: var(--space-1-5);
|
||||
min-width: 0;
|
||||
}
|
||||
.textareaWithButton > textarea {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.textareaWithButton > button {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
/* 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;
|
||||
resize: none;
|
||||
white-space: pre;
|
||||
overflow: auto;
|
||||
}
|
||||
.textarea:focus {
|
||||
box-shadow: inset 0 0 0 1px var(--focus-ring);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user