Enter Is Not Always Enter: IME Composition, Send Keys and Shortcuts in Agent Chat Inputs
Executive Summary
Agent products are chat products, and chat products bind Enter to send. For anyone typing Chinese, Japanese or Korean through an input method editor (IME), Enter has a second meaning: it commits the highlighted candidate. When both meanings fire on one key press, the user sends half-converted text such as nihongo instead of 日本語, and the next Enter sends an empty or duplicate message. The same collision hits Escape (cancel the candidate window, and also stop the agent or close the dialog), arrow keys (pick a candidate, and also scroll history), Tab and Backspace.
This bug class keeps coming back. Public trackers from recent months show it in agent composers, a Markdown comment widget, a design-system combo box, a desktop notes app and a Flutter shortcut binding. Whether the user is composing is a different signal on each platform, and in Safari the signal can arrive in an order that makes the obvious check wrong.
Main conclusions:
- On the web, check
event.isComposing || event.keyCode === 229in everykeydownhandler that acts on Enter, Escape, Tab or arrows. The UI Events specification says the key that ends a composition carriesisComposing: true; Safari has historically dispatchedcompositionendfirst, so that key arrives withfalse. MDN and Chrome's guidance both recommend the pair of checks. Hand-keptcompositionstart/compositionendflags fail for the same ordering reason. Treat the pair as a baseline filter onkeydown: it misses a Safari commit Enter reported with keyCode 13, and it cannot recognize the commit key'skeyup, which carries 13. - Safari is not a solved case. WebKit shipped, then reverted, a change that turned on correct composition event ordering in 2026. Keep the fallback permanently.
- Korean differs from Chinese and Japanese. In Chromium one Enter press at the end of a Hangul syllable produces two keydowns: a composing 229, then a plain 13. The filter skips the first and acts on the second, so that single press commits and sends. Decide whether that is what your product promises.
- Flutter on macOS also delivers the IME-consumed key to the framework. Open issue #190525 shows an Enter shortcut firing on the Japanese commit Enter; a maintainer called it working as intended. Guard on
TextEditingValue.composingyourself. - In AppKit, put send-on-Return in
doCommand(by:)(insertNewline:), not rawkeyDown, and gate window-level handlers onhasMarkedText(). - Soft keyboards differ. Android keyboards commonly report Enter as keyCode 229, so the desktop-Safari heuristic can disable send on phones. Do not bind Enter to send on touch devices.
- You cannot automate a real IME everywhere. Test the decision logic synthetically, use Chromium's DevTools Protocol to drive its own composition handling, and keep a manual checklist for real machines.
This article separates what a primary source says (specifications, MDN, Apple and Flutter documentation, bug trackers) from our own recommendation. Items we could not verify are listed in section 12.
1. The failure, step by step
A user types nihongo with a Japanese IME. The field shows underlined hiragana (the composition; marked text on macOS, the composing region in Flutter). The user presses Space to convert, sees candidate 日本語, and presses Enter to accept it. Two components want that keystroke: the IME, which uses Enter to commit, and the application, which uses Enter to send.
In the keyboard-driven composition the UI Events specification describes, the application receives that key too: keydown and keyup "MUST still be sent" during a composition session, and "MUST have the isComposing attribute set to true." The same specification's IME section also says that "some key events, or their values, might be suppressed by the IME in use," so this is the specified sequence, not a promise for every input method. In the desktop Chrome and Safari traces below the commit key does reach the page, and a bare if (e.key === "Enter") send() runs on it. That is the whole bug.
The specified order for a keyboard-driven composition is: first keydown (isComposing: false, the key that starts it), compositionstart, compositionupdate, further key events with true, the final keydown (true, "the key event that exits the composition"), compositionend, then keyup (false). Real browsers differ. What one physical Enter press produces:
- UI Events specification:
keydownwithisComposing: true, thencompositionend(W3C UI Events 3.6.5). - Chrome on macOS, Chinese or Japanese:
keydownEnter, keyCode 229,isComposing: true;compositionendafter (opencode PR #44826, description). - Chrome on macOS, Korean: two keydowns from the same press,
Enter/229/true, thenEnter/13/false(OpenSearch UI PR #1878, measured; memry PR #5821, trace). - Chrome on Windows 10, Microsoft Korean IME: two keydowns from the same press,
Process/229/true, thenEnter/13/false(OpenSearch UI PR #1878). - Safari on macOS, old ordering:
compositionendfirst; thenkeydownEnter,isComposing: false, usually keyCode 229 (WebKit 165004; assistant-ui #8319). - Safari 27 on macOS, Korean (one measurement): a single
Enter/13/falseaftercompositionend(OpenSearch UI PR #1878).
Two points matter later. The Safari fingerprint (229 with isComposing: false) is common but not universal: opencode PR #44826 reported keyCode 13 for the same event, and the Safari Korean measurement above shows 13. And in the Korean Chrome rows the plain Enter/13/false is not a second press by the user: the OpenSearch measurements list both keydowns for one Enter at the end of a syllable.
2. What the specifications say
isComposing. MDN: "returns a boolean value indicating if the event is fired within a composition session, i.e., after compositionstart and before compositionend." MDN marks it "Limited availability" (not Baseline).
keyCode 229. UI Events does not define keyCode values normatively. Its non-normative appendix (7.3.1) says: "If an Input Method Editor is processing key input and the event is keydown, return 229." MDN deprecates keyCode, yet its own keydown page uses it for this purpose and carries the note at the heart of this article: "compositionstart may fire after keydown when typing the first character that opens up the IME, and compositionend may fire before keydown when typing the last character that closes the IME. In these cases, isComposing is false even when the event is part of composition. However, KeyboardEvent.keyCode is still 229 in these cases."
key is not authoritative. The spec's IME section says keyboard events "cannot be used to determine the current state of the input method editor" and that "some key events, or their values, might be suppressed by the IME in use." Firefox reports key: "Process" for IME-handled keys (Mozilla bug 354358 and follow-ups), and the Windows Korean row above shows the same in Chrome. So e.key === "Enter" alone is too eager (it matches the commit) and too fragile (the commit key may not report key: "Enter").
Firefox history. Before Firefox 65 Firefox did not dispatch keydown/keyup during composition; since 65 they fire "to improve cross-browser compatibility for CJKT users" (MDN). The bug thread records that other browsers already did so and that WebKit developers believed sites would break otherwise. A comment there also recommends tracking text edits through input or compositionupdate, since voice and handwriting input methods fire no key events.
Cancellation. The spec says that if a keydown is canceled, composition events that would have followed "SHOULD not be dispatched," and that a canceled compositionstart ends the session. Calling preventDefault() on a composing key can therefore break the composition. Do not cancel keys you leave to the IME.
3. Web: the guard, and why Safari is special
3.1 The guard
Chrome's "Modern Web Guidance" article on IME-safe Enter-to-submit gives the pattern. Its advice: check isComposing, add keyCode === 229 as the fallback, nest the 229 check under the Enter condition (mobile virtual keyboards can report 229 for ordinary typing), submit with requestSubmit(), keep a real submit button, and note that Cmd+Enter and Ctrl+Enter "do not conflict with IME confirmation keys." Its snippet calls preventDefault() before the composing check. We recommend the reverse, for the cancellation reason above. The result is a baseline filter for keydown, not a complete guard:
el.addEventListener("keydown", (e) => {
if (e.key !== "Enter") return;
if (e.isComposing || e.keyCode === 229) return; // leave the key to the IME, untouched
if (e.shiftKey) return; // newline (textarea)
e.preventDefault();
send();
});
What it does not cover:
- A commit Enter that reports keyCode 13. opencode PR #44826 recorded Safari sending
compositionend, thenkeydownEnter withisComposing=falseandkeyCode=13, which the filter sends on. There, an editor that rewrote the DOM during composition made Safari split the composition; once the editor stayed inert while composing, the commit Enter reported 229. So first leave the field alone while composing; for any remaining 13, add the one-shotcompositionendwindow of section 3.4, which can also swallow a quick deliberate Enter after a candidate picked with the mouse. keypressandkeyuplisteners. The same check does not work there. In the WebKit 324380 trace (section 3.3) the commit key'skeyupcarried keyCode 13 andisComposing=false. Send only fromkeydown. If other code acts on Enter inkeypressorkeyup, have thekeydownfilter remember the key it skipped and ignore that key'skeypressandkeyupas well, which is what fixed the case in that report.- Korean. With the two keydowns Chrome sends for one Enter press (section 1), the filter skips the composing one and sends on the plain one, so the press that commits the syllable also sends. Section 8 covers the choice.
In React the synthetic keyboard event does not expose isComposing; read e.nativeEvent.isComposing (noted in a survey of merged IME fixes covering tag inputs, renames and autocompletes). React's onChange also fires on every composition update (facebook/react #3926, open since 2015), which can corrupt a composition if you transform the value.
3.2 Why a hand-written flag fails in Safari
WebKit bug 165004 ("The event order of keydown/keyup events and composition events are wrong on macOS," filed 2016-11-21 by Masayuki Nakano) is why: Safari dispatched compositionend before the keydown that ends the composition. A 2018 comment notes the spec says that keydown must carry isComposing === true, and concludes that checking keyCode 229 had become the only dependable detector. A flag cleared on compositionend is already false when the key arrives: "The root cause is the event order itself, so managing the composition events yourself doesn't get around it either" (one write-up).
Downstream trackers report the sequence compositionstart, input (isComposing: true), compositionend, keydown Enter with keyCode: 229 and isComposing: false (assistant-ui #8319, September 2026). The Escape that cancels a composition behaves the same way: OpenSearch UI PR #1878 fixed combo boxes, modals, flyouts and popovers closing on it.
3.3 The state of the Safari fix
- 2026-04-08: WebKit bug 311717, "Fix a regression and turn on correct composition event ordering by default." Bug 165004 was closed as a duplicate, with a commenter unable to reproduce on main.
- 2026-06-15: bug 317127 disabled the behavior everywhere: "We've been getting too many regression reports."
- 2026-09-16: bug 324380 reports that the "Correct key event ordering with composition events" feature flag does not affect macOS Web Apps added to the Dock, and that for sites sending on Enter this "can cause partially composed Chinese text to be submitted unintentionally." A 2026-10-16 comment reports a messaging site misbehaving in both Safari and the web app on a newer macOS:
compositionend, thenkeydownEnter keyCode 229isComposing=false, thenkeyupEnter keyCode 13isComposing=false. A keydown-only guard did not fix that user's case; stopping propagation of that one physical key's keydown, keypress and keyup, withoutpreventDefault(), did, and the next ordinary Enter still went through.
Reading: do not assume the spec order in Safari or any WebKit view (WKWebView, Tauri on macOS). Keep the 229 fallback on keydown. A keyup handler cannot use the same check, because the commit key's keyup reports 13; handle it as section 3.1 describes.
3.4 Timestamp guards
Editors cannot rely on isComposing, so they add a time window after compositionend:
- ProseMirror (
input.ts): on Safari, a keydown within 500 ms ofcompositionEndedAtis ignored once, then the timestamp resets, as "pressing Enter a second time should insert a newline." The code comment adds that the timestamps must be close so that a confirmation done with the mouse followed by a later keydown is not ignored; a keydown inside the 500 ms still is. - CodeMirror (
input.ts): ignores keys while composing; on non-iOS Safari it also ignores one key within 100 ms ofcompositionendwhile itscompositionPendingKeyflag is set, then clears the flag. - Chrome's guidance: record
event.timeStampatcompositionendand skip Enter within 50 ms. Safari fires them "often within 5ms"; use the absolute difference andtimeStamp, notDate.now(). - Application fixes: 30 ms (omnara, "a choice, not a measured constant"), 100 ms (opencode), 60 and 80 ms elsewhere.
Window sizes ranging from 5 to 500 ms suggest none was measured against a population. Two design points hold across careful implementations. Make the guard one-shot, consumed when it fires, so the next deliberate Enter works. And prefer the stateless pair where it works: omnara replaced its timer with it before merging (November 3, 2026), and Sentry's composer fix (PR #125665) uses it too; its test in mentionComposer.spec.tsx dispatches a Safari-shaped keydown (keyCode 229, isComposing: false) after compositionend, checks that nothing was submitted, then presses a separate plain Enter and checks that the comment is submitted. Add a timer only if you observe keyCode 13 in a real trace, and accept its cost: any window long enough to cover the late key also swallows an Enter pressed that quickly after a candidate picked with the mouse, because that pick also fires compositionend. Users also press Enter fast (confirm, confirm, send), so a debounce alone is not enough.
3.5 Rich-text editors and global guards
Editors that own the contenteditable (ProseMirror, CodeMirror, Lexical) track composition themselves, so wrapping them adds a second place where Enter is interpreted. ProseMirror issue #1190 (2021, closed September 2024 via prosemirror-view PR #97) shows the subtlety: in Safari with the Japanese IME, Enter after composition inserted a line break when stored marks were active, because Safari fires the MutationObserver before keydown and compositionend. assistant-ui #8319 notes Lexical's own Safari handling covers only Backspace, so the confirming Enter reaches KEY_ENTER_COMMAND; the fix (PR #8336) is the stateless pair. Intercept in the editor's DOM-event layer and do not cancel the event while composing.
Per-field checks drift. A desktop notes app (memry PR #5821, merged November 25, 2026) counted 143 renderer files with Enter or Escape handlers lacking a composition check and added one capture-phase keydown listener on window that stops composing events aimed at <input> and <textarea>, leaving contenteditable editors alone. Another project (thinkrail PR #879, merged November 2, 2026) used per-field helpers, a fix in the dialog and popover primitive (wrapping onEscapeKeyDown) and a source-scan test that fails when a file with a text field and a key handler skips the guard. The first buys coverage cheaply but can hide keys from shortcut code; the second is explicit but needs a drift check.
4. Mobile soft keyboards
On touch devices the Enter key is a button on a keyboard that is itself an IME.
- Android Chrome with Gboard: the primary record we found is a 2018 Chromium issue (41368867, formerly crbug 809107, closed as Won't Fix). There a Chromium developer explained that keyboard events showing "Unidentified/229" indicate whether Enter was pressed inside a composition: outside one, Gboard produces an ordinary Enter; inside one, Gboard is probably turning it into a compose text message "and we generate a 229 for that." Another Chromium developer closed the issue with the advice to use the
beforeinputevent with theinsertParagraphcommand to handle Enter. A later bug report (Froala #4546, closed as not planned) summarizes the thread as "Chrome will send key code 229 instead of 13, which is intentional behavior that Chrome doesn't intend to change." We did not test a current Gboard build. - One project (imbue PR #1129, merged November 18, 2026) therefore dropped the 229 check, since "some Android on-screen keyboards are reported to give an ordinary Enter that code" and counting it "would stop Enter from sending on those phones." It accepts that "Safari and iOS can still send early."
- HTML
enterkeyhint(MDN: baseline since November 2021) labels the virtual Enter key withenter,done,go,next,searchorsend.
Our recommendation, not a sourced rule: on touch-primary devices make Enter insert a newline, send with an on-screen button and use enterkeyhint="enter". You then never interpret Enter, so the 229 conflict disappears. Keep Enter-to-send for hardware keyboards, with the 229 check inside the Enter branch. If you must send on a phone, also handle the line-break beforeinput (insertParagraph, as the Chromium thread advises) and deduplicate. In the same thread the reporter found that preventDefault() on the Gboard Enter keydown did not stop the line break, and a Chromium developer replied that "we do not currently support canceling IME commands," so handling both events can send twice.
5. Flutter
TextEditingValue.composing holds the range of text "that is still being composed"; TextRange.empty means "the text is not currently being composed." The docs add that it is also used for Latin autocorrect words and, on iOS 17+, inline predictions, so a valid range is not always a CJK conversion. For a send guard that is fine: while it is valid, Enter should not send.
5.1 Key events reach the framework first
DefaultTextEditingShortcuts documentation: "Shortcuts prevent text input fields from receiving their keystrokes as text input," because the engine first offers each keystroke to the framework as a raw key event through SystemChannels.keyEvent: "If it is not handled, then it will proceed to try handling it as text input through SystemChannels.textInput." That is what lets Shortcuts override platform bindings, and also what puts app shortcuts ahead of the IME. KeyEventResult gives the outcomes of a Focus.onKeyEvent handler: handled (not propagated further), ignored (it "should continue to be propagated to other key event handlers, even non-Flutter ones") and skipRemainingHandlers (not passed to other handlers; it "will be returned to the platform embedding to be propagated to text fields and non-Flutter key event handlers on the platform"). RawKeyboard is deprecated; use HardwareKeyboard and KeyEvent.
5.2 The macOS issue
Flutter issue #190525 (filed August 4, 2026; platform-macos, a: text input, found in 3.44) is the Flutter instance of this bug. The reporter binds Enter with CallbackShortcuts around a multi-line TextField, converts Japanese text and presses Enter: "On macOS the same enter press commits the conversion and also fires the binding," and Focus.onKeyEvent also receives it. Impact: with an Enter-to-send chat UI, "Japanese (and Chinese/Korean) users end up sending the message every time they confirm a conversion." The reporter says it does not happen on Windows, where IME-consumed keys arrive as VK_PROCESSKEY and never reach shortcuts, nor in native macOS apps, and suggests ignoring Enter while controller.value.composing.isValid.
Maintainers disagree:
- A text-input contributor (September 3) called it "more of a framework issue": the app's Enter binding overrides the macOS default
SingleActivator(enter): DoNothingAndStopPropagationTextIntent(), the entry that normally sends the event back to the embedder and on to the IME. They suggested wrapping the field inDefaultTextEditingShortcutsand acknowledged "there probably should be an easier way to add shortcuts without breaking IME interactions." - A member (October 19) said "This works as intended," conceded the platform divergence is not ideal, wrote "I don't think there's a good way to determine on macOS if IME has handled key event or not," and recommended
onEditingComplete, which "does the right thing" when no candidate selection is active.
The proposed engine fix, PR #190538 ("[macOS] Offer key events to the IME before the framework while composing," open and "waiting for response" on November 12), sends key-downs to the text input system first while marked text exists and swallows the matching key-ups. Reviewers objected that keying off the composing region "feels like a heuristic/not-always-reliable"; another suggested always sending Enter and Escape straight to the text input plugin during composition.
Related: issue #85328 (2021), arrow keys moving the caret instead of choosing a Pinyin candidate on macOS, closed in July 2022 after the engine began sending editing intents; open iOS PR #193573 defers arrow keys to the IME while composing, where a reviewer noted some macOS Japanese IMEs "move cursor even if compositing. This doesn't seem like something we can fix in the framework." Flutter web had a variant (#136460: a key marked handled still reached the IME; fixed October 2023).
5.3 A defensible pattern
Do not rely on one layer. Read composition state when the key arrives and decline to claim the key:
// Sketch only; not compiled or run by us.
KeyEventResult onKey(FocusNode node, KeyEvent event) {
if (event is! KeyDownEvent) return KeyEventResult.ignored;
if (event.logicalKey != LogicalKeyboardKey.enter &&
event.logicalKey != LogicalKeyboardKey.numpadEnter) {
return KeyEventResult.ignored;
}
if (controller.value.composing.isValid) return KeyEventResult.ignored; // IME owns it
if (HardwareKeyboard.instance.isShiftPressed) return KeyEventResult.ignored; // newline
send();
return KeyEventResult.handled;
}
Attach it with Focus(onKeyEvent: ...) around the field. Returning ignored does not hand the key straight to the platform: the event first continues to ancestor Flutter handlers (parent Focus and Shortcuts widgets, up to DefaultTextEditingShortcuts near the root), and returns to the engine and the IME only if none of them handles it. So an Enter binding higher in the tree can still fire; keep such bindings off Enter or give them the same composing check. The check happens at key-down; on macOS the framework sees the key before the commit, so the range is still valid. Apply the same guard to Escape and arrow-key history; the thread says nobody can tell on macOS whether the IME consumed an Escape.
Two places that look equivalent are not. A CallbackShortcuts callback is a VoidCallback, and CallbackShortcuts returns handled for any binding whose activator matches, so an early return inside the callback still consumes the key. In an Action, returning early from invoke does not release the key either: the result comes from toKeyEventResult, which by default returns handled when consumesKey returns true (the default) and skipRemainingHandlers when it returns false. The framework invokes the action first and only then computes that result, so an Action needs both steps: while composing, have invoke skip the send and have consumesKey return false. Per its documentation, a key that is not handled "will be passed back to the engine, and continue to be processed there, allowing text fields and non-Flutter widgets to receive the key event." We read this in the Flutter source and did not run it.
6. Native macOS (AppKit)
Apple documents NSTextInputClient as methods that text views "need to implement to interact properly with the text input management system." hasMarkedText() reports "whether the receiver has marked text"; on unmarkText() the text view "should accept the marked text as if it had been inserted normally." interpretKeyEvents(_:) "sends the character input in eventArray to the system input manager for interpretation as text to insert or commands to perform," and the input manager answers with insertText and doCommand(by:). NSTextInputContext.handleEvent(_:) reports whether the system consumed the event.
Our reading of that contract (the pages do not state it as a rule): do not decide on Return in keyDown(with:). Pass the event to the input system first. Plain Return with no composition arrives as the insertNewline: command via doCommand(by:); a Return the IME uses to commit arrives as insertText/unmarkText. Put send-on-Return in the insertNewline: handler. Handle Shift+Return as a literal newline in keyDown only when hasMarkedText() is false; while marked text exists, pass Shift+Return to the text input system first like every other key, as the section 8 rule requires.
Window- and app-level handlers are where native apps still break. Telegram's macOS client (issue #458, November 20, 2026, open) reports window-level arrow handlers running before the responder chain, so the candidate window never sees the arrows. The proposed guard checks whether window.firstResponder is an NSTextInputClient with hasMarkedText() and, if so, passes the event on; the issue says an earlier PR fixed Return the same way. This is the AppKit analogue of the web's global capture guard.
7. Electron and web views
Electron renders with Chromium, so the web guard and the Chromium traces in section 1 apply. Electron's main-process before-input-event exposes isComposing ("Equivalent to KeyboardEvent.isComposing"), and event.preventDefault() there "will prevent the page keydown/keyup events and the menu shortcuts," so main-process shortcuts should check input.isComposing first. The structure has no keyCode, so it cannot catch a Safari-style late key; we saw no such case in Chromium traces.
A webview on macOS (WKWebView, Tauri) inherits WebKit's order: omnara PR #541 says the bug "also affects anything on WKWebView," and memry kept a follow-up WebKit test where Enter arrives as 229 after compositionend (#5830). Embedded terminals are special: thinkrail left its terminal's existing 229 handling alone, so review them separately.
8. What each key should do
This is our recommendation, built from the specification and the cases above. Composing means isComposing or keyCode === 229 on a web keydown, a valid composing range (Flutter) or hasMarkedText() (AppKit). Rule: while composing, the application does nothing and cancels nothing.
- Enter. Composing: nothing; no
preventDefault. Not composing: send (Enter-sends mode) or newline (Cmd/Ctrl+Enter-sends mode). - The plain Enter keydown a Korean commit press also emits (
Enter/13/falseafter the composing 229, section 1). Composing: does not apply; it is not composing, and the user has not pressed again. Not composing: the filter treats it as Enter, so the press that commits the syllable also sends. If that is the product's choice, the filter delivers it. If the product promises commit first and send on a second press, it cannot: the handler would have to tell that this keydown belongs to the same physical press as the composing one, which no cited measurement tested. - Shift+Enter. Composing: nothing; the IME handles it. Not composing: newline.
- Cmd/Ctrl+Enter. Composing: nothing (precaution; Chrome's guide says no check is needed). Not composing: send.
- Escape. Composing: nothing; the IME cancels its candidate. Do not stop the agent, close the dialog or clear the draft. Not composing: stop generation, then close popover, then clear.
- Up / Down. Composing: nothing; they move through candidates. Not composing: move the caret; recall history only on the first or last line or an empty field.
- Left / Right. Composing: nothing; some IMEs move inside the composing region. Not composing: move the caret.
- Tab, Backspace, Space. Composing: nothing. Not composing: accept suggestion or move focus; edit; type.
- Single-key shortcuts (
/,?). Composing: never fire. Not composing: our recommendation is not to fire them while focus is in a text input either (section 10.2).
Escape matters more in agent products than in chat, because it often means stopping the run. One public report (opencode #62290, closed November 6, 2026) has a macOS Pinyin user dismissing the candidate window with Escape and also stopping the agent, with no setting to change it. An Up-arrow history rule needs a caret condition even outside composition, or it replaces a multi-line draft.
9. Newline conventions and the send key
Chat products have converged on Enter to send and Shift+Enter for a newline. Slack's help center documents an Enter key preference: with Send the message, Shift+Enter starts a new line; with Start a new line, ⌘+Enter (Mac) or Ctrl+Enter (Windows/Linux) sends. Sentry's recent comment composer (PR #125665) takes the same shape: Enter submits, Shift+Enter inserts a line break, Ctrl/Cmd+Enter also submits, and IME composition is checked before the form's key handler.
For an agent product a setting is more justified than in human chat. Prompts are longer and more often multi-line (logs, code), so accidental sends are expensive, and CJK users hit the composition collision most. A Claude Code user (#8455, September 2025) asked that the first Enter only confirm the conversion and a second Enter send, calling this "the standard behavior in other chat applications like Slack, Discord, and Teams." Another request in that tracker (#89673) asks for a desktop option making Enter a newline and Ctrl+Enter submit. Offer Enter sends and Cmd/Ctrl+Enter sends, Enter inserts a newline, and show the active mapping next to the input.
10. Testing and accessibility
10.1 Testing
You cannot reliably drive a real IME from CI, so split the problem.
Synthetic tests. Extract the decision into a pure function over a small structure (key, keyCode, isComposing, modifiers, msSinceCompositionEnd) returning send, newline, ignore or pass-through, and test every case in section 8, including the Safari fingerprint (isComposing: false, keyCode: 229), the Safari commit Enter with keyCode 13, and the Korean press that emits two keydowns. KeyboardEventInit accepts isComposing, so a synthetic keydown can carry it; define legacy keyCode explicitly. Dispatch compositionstart/update/end yourself to test one-shot flags. In Flutter, TestTextInput.updateEditingValue ("Simulates the user changing the TextEditingValue") can set a non-empty composing range, then send Enter and assert nothing was sent; its docs warn it can confuse a real IME connection, so keep it in widget tests. Synthetic tests prove your logic for the shapes you modeled, not that browsers produce them: the Safari bug is exactly where hand-dispatched events pass and reality fails.
Chromium's own composition handling. The DevTools Protocol has Input.imeSetComposition (it "sets the current candidate text for IME," experimental) and Input.insertText (it "emulates inserting text that doesn't come from a key press," experimental). So the protocol can set a composition and insert text; it does not say that the two in sequence reproduce a physical keyboard's IME commit events, and we did not run it. One harness we found (OpenSearch Dashboards PR #13044) built a real composition with imeSetComposition and then sent the keydowns measured on real machines itself. It covers Chromium only. Playwright has no IME API: its feature request (#5777) was closed as not planned on October 31, 2026, the maintainer noting this "doesn't mean the request is wrong." Firefox and WebKit have no standard hook.
Manual checklist on real hardware, before releases touching the composer; record OS, browser and IME versions, since ordering changed by version:
- macOS Safari (plus any WKWebView build or Dock web app) with Pinyin and Japanese: type, convert with Space, Enter. Expect commit without sending; a second Enter sends.
- macOS Chrome with Pinyin, Japanese and Korean (Korean: syllable then one Enter press; behavior must match the product decision and lose no text).
- Windows Chrome or Edge with Microsoft Pinyin, Japanese and Korean; Firefox on both desktop systems.
- Flutter macOS and web builds with Japanese and Pinyin; Windows for comparison.
- Android Chrome with Gboard and a Chinese keyboard; iOS Safari with Pinyin. Enter must act exactly once.
- Everywhere: Escape in a candidate window (must not stop the agent), arrows through candidates, Backspace, Shift+Enter, rapid Enter-Enter, and mouse-picking a candidate then Enter (the next Enter must work; this catches timers that swallow too much).
10.2 Accessibility
- Keep a visible, labeled Send button. Chrome's guide: keyboard shortcuts "must not replace native form submit paths." This also serves voice, switch and screen-reader users.
- Character-key shortcuts. WCAG 2.1 SC 2.1.4 (Level A) covers shortcuts made "using only letter (including upper- and lower-case letters), punctuation, number, or symbol characters." Enter is none of these, so Enter-to-send is outside its scope. A global
/or?shortcut is inside it and complies if users can turn it off, can remap it to include a non-printable key such as Ctrl or Alt, or if it is "only active when that component has focus." Not firing such shortcuts while focus is in a text input is our product recommendation on top of that: IMEs use those characters too. - Do not detect text through key events. Dictation, handwriting and some IMEs produce text without them; read
beforeinput/input. - Let users choose the send key and show the mapping. It helps IME users, people with tremor who hit Enter by accident, and anyone composing long prompts.
- Confirm sends to screen readers with a polite live region (for example, Message sent); stay silent when Enter merely commits a candidate. (Our recommendation.)
11. Recommendations for an agent chat product
- One composition check per platform, called first in every key handler. Web:
isComposing || keyCode === 229onkeydown, as a baseline filter; send only fromkeydown, and make anykeypressorkeyupcode skip a key whosekeydownwas skipped (section 3.1). Flutter: a validcomposingrange. AppKit:hasMarkedText(), or send-on-Return indoCommand(by:). The public record shows missed spots in autocompletes, renames, popovers and dialog Escape; centralize the check (a shared helper plus a drift test, or a global capture guard). - Cover Escape, Tab, arrows and Backspace, not only Enter. In agent products Escape usually stops the run, so a missed guard costs more than an early send.
- Never
preventDefault()or returnhandledfor a key you leave to the IME. Check composition first, then cancel the default for a true send. - Keep the 229 fallback permanently for Safari and every WebKit view and re-test per OS version. Add a short, one-shot timestamp window after
compositionendonly if you see keyCode 13 in a real trace, knowing it can also swallow a quick Enter after a candidate picked with the mouse. - Decide Korean on purpose. In Chromium the baseline filter commits and sends on the one Enter press that ends a Hangul syllable. Keep that, or promise commit-then-send and build more than the filter (section 8). Test whichever you choose.
- Make the send key a setting, show it, keep a Send button. Default to Enter-sends on desktop and a newline Enter on touch devices.
- In Flutter, guard at the call site (
Focus.onKeyEvent, or anActionthat, while composing, skips the send ininvokeand returns false fromconsumesKey; not aCallbackShortcutscallback) until issues #190525 and #190538 settle, and add a widget test withTestTextInput.updateEditingValue. - Share one written key list (section 8) and one manual checklist across web, mobile and desktop clients, and regress all three when one changes.
- Test logic synthetically and reality manually, and record versions.
- Make send undoable where you can. An accidental send in an agent product starts work; an undo or edit-and-resend path limits the damage while platform bugs remain.
12. What we could not verify
- Android Enter as keyCode 229: the Chromium statements come from a 2018 issue thread (41368867); we found no newer primary record and tested no current Gboard or Chrome build.
- Safari in shipping builds after October 2026: WebKit's tracker shows a fix landed and was disabled, and a later report says it misses web apps. We tested no Safari release; keyCode 229 versus 13 for the late Enter differs between reports.
- Korean conventions: the Chromium traces on two operating systems are other projects' measurements, and we found no source for what users expect in every chat product, so the Korean behavior is a product decision. No cited measurement tested a handler that skips the plain keydown of the same press.
- ChatGPT, Slack and Discord: no primary source found for their IME handling; they appear in trackers only as apps users cite as getting it right. Slack's help center documents its Enter key preference, not its IME handling.
- Return during composition in AppKit: the Apple pages define the methods and routing but do not state when
insertNewline:is delivered; that is our reading. - CDP composition: we read the protocol definitions, which describe setting a composition and inserting text separately. We found no trace showing that the two in sequence produce a physical keyboard's IME commit events, and ran none.
- Flutter on Windows and Linux: the claim that IME-consumed keys never reach
Shortcutson Windows comes from the issue reporter and PR description. We ran no Flutter code; the Dart sketch and theCallbackShortcuts/Actionbehavior come from reading the Flutter source. - Fix contents for VS Code #336899 (closed November 25, 2026, no linked PR on the page) and opencode's Escape issue #62290 (closed via #62318): status read, code not.
References
Specifications and platform documentation
- W3C UI Events (3.5.1.1, 3.6.4, 3.6.5, 4.3.3, 7.3.1): https://www.w3.org/TR/uievents/
- MDN
isComposing: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/isComposing - MDN
keydownevent: https://developer.mozilla.org/en-US/docs/Web/API/Element/keydown_event - MDN
keyCode: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode - MDN
enterkeyhint: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/enterkeyhint - Chrome for Developers, IME-safe enter-to-submit: https://developer.chrome.com/docs/modern-web-guidance/guides/forms/ime-safe-enter-submit
- Apple
NSTextInputClient: https://developer.apple.com/documentation/appkit/nstextinputclient ;hasMarkedText(): https://developer.apple.com/documentation/appkit/nstextinputclient/hasmarkedtext() ;unmarkText(): https://developer.apple.com/documentation/appkit/nstextinputclient/unmarktext() ;interpretKeyEvents(_:): https://developer.apple.com/documentation/appkit/nsresponder/interpretkeyevents(_:) - Flutter
TextEditingValue.composing: https://api.flutter.dev/flutter/services/TextEditingValue/composing.html ;DefaultTextEditingShortcuts: https://api.flutter.dev/flutter/widgets/DefaultTextEditingShortcuts-class.html ;KeyEventResult: https://api.flutter.dev/flutter/widgets/KeyEventResult.html ;TestTextInput.updateEditingValue: https://api.flutter.dev/flutter/flutter_test/TestTextInput/updateEditingValue.html ;Action.consumesKey: https://api.flutter.dev/flutter/widgets/Action/consumesKey.html ;Action.toKeyEventResult: https://api.flutter.dev/flutter/widgets/Action/toKeyEventResult.html - Flutter source,
CallbackShortcutsandShortcuts: https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/shortcuts.dart ;Action: https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/actions.dart - Electron
before-input-event: https://github.com/electron/electron/blob/main/docs/api/web-contents.md - Chrome DevTools Protocol, Input domain: https://chromedevtools.github.io/devtools-protocol/tot/Input/ ; definition: https://github.com/ChromeDevTools/devtools-protocol/blob/master/pdl/domains/Input.pdl
- WCAG 2.1 SC 2.1.4: https://www.w3.org/WAI/WCAG21/Understanding/character-key-shortcuts.html
Browser bug trackers
- WebKit: https://bugs.webkit.org/show_bug.cgi?id=165004 , https://bugs.webkit.org/show_bug.cgi?id=311717 , https://bugs.webkit.org/show_bug.cgi?id=317127 , https://bugs.webkit.org/show_bug.cgi?id=324380
- Mozilla 354358: https://bugzilla.mozilla.org/show_bug.cgi?id=354358
- Chromium 41368867 (formerly crbug 809107): https://issues.chromium.org/issues/41368867
Flutter
- https://github.com/flutter/flutter/issues/190525 , https://github.com/flutter/flutter/pull/190538 , https://github.com/flutter/flutter/issues/85328 , https://github.com/flutter/flutter/pull/193573 , https://github.com/flutter/flutter/issues/136460
Editors, libraries and tooling
- https://github.com/ProseMirror/prosemirror-view/blob/master/src/input.ts , https://github.com/ProseMirror/prosemirror/issues/1190
- https://github.com/codemirror/view/blob/main/src/input.ts
- https://github.com/facebook/react/issues/3926
- https://github.com/assistant-ui/assistant-ui/issues/8319
- https://github.com/microsoft/playwright/issues/5777
- Survey of merged IME fixes: https://dev.to/mahirhir/15-merged-ime-fixes-the-recurring-ways-japanese-typing-breaks-web-apps-55no
- Write-up on isComposing and keyCode 229: https://azukiazusa.dev/en/blog/ime-enter-submit/
Products and applications
- Claude Code: https://github.com/anthropics/claude-code/issues/8455
- VS Code: https://github.com/microsoft/vscode/issues/336899
- OpenSearch UI: https://github.com/opensearch-project/oui/pull/1878
- OpenSearch Dashboards: https://github.com/opensearch-project/OpenSearch-Dashboards/pull/13044
- Sentry: https://github.com/getsentry/sentry/pull/125665 ; test changes: https://github.com/getsentry/sentry/pull/125665/files
- omnara: https://github.com/omnara-ai/omnara/pull/541
- opencode: https://github.com/anomalyco/opencode/pull/44826 , https://github.com/anomalyco/opencode/issues/62290
- memry: https://github.com/memrynote/memry/pull/5821
- thinkrail: https://github.com/JetBrains/thinkrail/pull/879
- imbue: https://github.com/imbue-ai/default-workspace-template/pull/1129
- Telegram macOS: https://github.com/TelegramMessenger/telegram-macos/issues/458
- Froala: https://github.com/froala/wysiwyg-editor/issues/4546
- Slack, Set your Enter key preference: https://slack.com/help/articles/115005523006-Edit-your-message-preferences
