fix: ctrl+enter键不能换行的问题
This commit is contained in:
parent
1166a65505
commit
22f616ab2a
|
|
@ -883,7 +883,32 @@ export const PromptInputTextarea = ({
|
||||||
if (!submitOnEnter) {
|
if (!submitOnEnter) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.shiftKey || e.ctrlKey || e.metaKey) {
|
if (e.shiftKey || e.ctrlKey || e.metaKey) {
|
||||||
|
// Keep newline behavior explicit for modified-Enter combos.
|
||||||
|
// This avoids accidental submit shortcuts swallowing Ctrl/Cmd+Enter.
|
||||||
|
if (e.ctrlKey || e.metaKey) {
|
||||||
|
e.preventDefault();
|
||||||
|
const target = e.currentTarget;
|
||||||
|
const start = target.selectionStart ?? target.value.length;
|
||||||
|
const end = target.selectionEnd ?? target.value.length;
|
||||||
|
const nextValue =
|
||||||
|
target.value.slice(0, start) + "\n" + target.value.slice(end);
|
||||||
|
|
||||||
|
if (controller) {
|
||||||
|
controller.textInput.setInput(nextValue);
|
||||||
|
} else {
|
||||||
|
target.value = nextValue;
|
||||||
|
const inputEvent = new Event("input", { bubbles: true });
|
||||||
|
target.dispatchEvent(inputEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Place caret right after the inserted newline.
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
target.selectionStart = start + 1;
|
||||||
|
target.selectionEnd = start + 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue