Make Enter insert newline on mobile devices

On mobile devices, pressing Enter now inserts a newline (hardBreak) instead
of submitting the message. This provides better UX since mobile keyboards
don't have easy access to Shift+Enter for multiline input.

Behavior:
- Desktop: Enter submits, Shift+Enter inserts newline (unchanged)
- Mobile: Enter inserts newline, Cmd/Ctrl+Enter submits
- Mobile detection: Uses touch support API (ontouchstart or maxTouchPoints)

Users can still submit messages on mobile using:
1. The Send button (primary method)
2. Ctrl+Enter keyboard shortcut (if available)
This commit is contained in:
Claude
2026-01-13 19:45:57 +00:00
parent 585eed5135
commit 61cdc5cd66

View File

@@ -667,6 +667,9 @@ export const MentionEditor = forwardRef<
// Build extensions array
const extensions = useMemo(() => {
// Detect mobile devices (touch support)
const isMobile = "ontouchstart" in window || navigator.maxTouchPoints > 0;
// Custom extension for keyboard shortcuts (runs before suggestion plugins)
const SubmitShortcut = Extension.create({
name: "submitShortcut",
@@ -677,10 +680,16 @@ export const MentionEditor = forwardRef<
handleSubmitRef.current(editor);
return true;
},
// Plain Enter submits (Shift+Enter handled by hardBreak for newlines)
// Plain Enter behavior depends on device
Enter: ({ editor }) => {
handleSubmitRef.current(editor);
return true;
if (isMobile) {
// On mobile, Enter inserts a newline (hardBreak)
return editor.commands.setHardBreak();
} else {
// On desktop, Enter submits the message
handleSubmitRef.current(editor);
return true;
}
},
};
},