From 22f616ab2aa6e452aefc56bc0dcdafae576fe681 Mon Sep 17 00:00:00 2001 From: MT-Mint <798521692@qq.com> Date: Sat, 11 Apr 2026 14:38:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ctrl+enter=E9=94=AE=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ai-elements/prompt-input.tsx | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/frontend/src/components/ai-elements/prompt-input.tsx b/frontend/src/components/ai-elements/prompt-input.tsx index 682b804e..53491204 100644 --- a/frontend/src/components/ai-elements/prompt-input.tsx +++ b/frontend/src/components/ai-elements/prompt-input.tsx @@ -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();