mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
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:
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user