fix: ctrl+enter键不能换行的问题

This commit is contained in:
肖应宇 2026-04-11 14:38:53 +08:00 committed by Titan
parent 40e252a74e
commit 41c6d7cf65
1 changed files with 25 additions and 0 deletions

View File

@ -883,7 +883,32 @@ export const PromptInputTextarea = ({
if (!submitOnEnter) {
return;
}
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;
}
e.preventDefault();