Skip to content

An AI-powered search engine with a generative UI

fix(chat): treat Opt/Cmd/Ctrl+Enter as newline, not submit (#848)

Eliauk8c19c79a9d25
diff --git a/components/chat-panel.tsx b/components/chat-panel.tsx
index 42873fe2..6c359f38 100644
--- a/components/chat-panel.tsx
+++ b/components/chat-panel.tsx
@@ -270,11 +270,16 @@ export function ChatPanel({
className="resize-none w-full min-h-12 bg-transparent border-0 p-3 md:p-4 text-sm placeholder:text-muted-foreground focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-50"
onChange={handleInputChange}
onKeyDown={e => {
+ if (e.key !== 'Enter' || isComposing || enterDisabled) {
+ return
+ }
+
+ // Plain Enter (no modifiers) → submit
if (
- e.key === 'Enter' &&
!e.shiftKey &&
- !isComposing &&
- !enterDisabled
+ !e.altKey &&
+ !e.metaKey &&
+ !e.ctrlKey
) {
if (input.trim().length === 0) {
e.preventDefault()
@@ -283,9 +288,26 @@ export function ChatPanel({
e.preventDefault()
const textarea = e.target as HTMLTextAreaElement
textarea.form?.requestSubmit()
- // Reset focus state after Enter key submission
setIsInputFocused(false)
textarea.blur()
+ return
+ }
+
+ // Shift+Enter falls through to textarea default (inserts \n).
+ // Alt/Option+Enter on macOS does NOT insert \n by default,
+ // so insert it manually to match user expectation.
+ if (e.altKey && !e.shiftKey && !e.metaKey && !e.ctrlKey) {
+ e.preventDefault()
+ const textarea = e.target as HTMLTextAreaElement
+ const start = textarea.selectionStart ?? input.length
+ const end = textarea.selectionEnd ?? input.length
+ const next = input.slice(0, start) + '\n' + input.slice(end)
+ handleInputChange({
+ target: { value: next }
+ } as React.ChangeEvent<HTMLTextAreaElement>)
+ requestAnimationFrame(() => {
+ textarea.selectionStart = textarea.selectionEnd = start + 1
+ })
}
}}
/>
diff --git a/components/user-text-section.tsx b/components/user-text-section.tsx
index 5a996447..42da1df2 100644
--- a/components/user-text-section.tsx
+++ b/components/user-text-section.tsx
@@ -84,7 +84,29 @@ export const UserTextSection: React.FC<UserTextSectionProps> = ({
return
}
- if (event.shiftKey || isComposing || enterDisabled) {
+ // Any modifier (Shift / Alt / Meta / Ctrl) + Enter → let it insert a
+ // newline instead of submitting the edit.
+ if (
+ event.shiftKey ||
+ event.altKey ||
+ event.metaKey ||
+ event.ctrlKey ||
+ isComposing ||
+ enterDisabled
+ ) {
+ // Alt+Enter on macOS does not insert \n by default; do it manually.
+ if (event.altKey && !event.shiftKey && !event.metaKey && !event.ctrlKey) {
+ event.preventDefault()
+ const textarea = event.target as HTMLTextAreaElement
+ const start = textarea.selectionStart ?? editedContent.length
+ const end = textarea.selectionEnd ?? editedContent.length
+ const next =
+ editedContent.slice(0, start) + '\n' + editedContent.slice(end)
+ setEditedContent(next)
+ requestAnimationFrame(() => {
+ textarea.selectionStart = textarea.selectionEnd = start + 1
+ })
+ }
return
}