Skip to content

fix(studio): allow Enter to send with idle macOS Pinyin IME - #12138

Merged
danielhanchen merged 6 commits into
unslothai:mainfrom
Souravrajvi0:feat/macos-pinyin-enter-send-207e
Oct 2, 2026
Merged

danielhanchen merged 6 commits into
unslothai:mainfrom
Souravrajvi0:feat/macos-pinyin-enter-send-207e

Conversation

@Souravrajvi0

@Souravrajvi0 Souravrajvi0 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #12137.

With macOS built-in Pinyin selected, plain Enter in Chat did not send while Cmd+Enter still worked. The composer treated every IME-marked Enter (isComposing or keyCode 229) as candidate confirmation and returned before submit, even when no composition was open.

Fix

  • Track whether a composition is open (compositionstart to compositionend, reset on blur) and when the last one ended.
  • A plain IME-marked Enter with no composition open now takes the normal submit path (imeKeydownBlocksComposerSubmit, composerKeyEventForImeSubmit), in both the main composer and the compare composer.
  • WebKit (Safari and the macOS desktop app) fires compositionend before the keydown of the Enter that confirms a candidate, and that keydown carries keyCode 229 (WebKit bug 165004). A keyCode 229 keydown within 500 ms of compositionend stays IME-owned, the same window ProseMirror uses, so confirming a Japanese or Chinese conversion never sends.
  • Modifier chords, Enter during an open composition, and the stuck-composition guards are unchanged.

Tests

  • studio/frontend/tests/composer-ime-enter.test.ts
  • studio/frontend/tests/composer-submit-path.test.ts: the shipped main-composer handler sends an idle IME Enter and holds the WebKit confirming Enter
  • tests/studio/test_composer_rtl_bidi_attribute.py: the stuck-Enter source checks now look only at the stuck-composition block
cd studio/frontend && node --experimental-strip-types --test tests/composer-ime-enter.test.ts tests/composer-submit-path.test.ts

Before / after

Both builds (merge base and this PR) were installed side by side. The same key sequences were replayed on the real composer textarea in Chromium and WebKit. The events are synthetic, since headless browsers have no OS input method.

Plain Enter with keyCode 229 and no composition open (idle macOS Pinyin). Before: the draft stays in the composer. After: it is sent.

Idle IME Enter, before vs after

WebKit's candidate-confirming order (compositionstart, compositionend, then keydown Enter with keyCode 229). The draft stays unsent on both sides, so confirming a conversion never sends. The greeting line is picked at random, and the Recents entry on the right is the chat from the first run.

Candidate-confirming Enter, before vs after

case engine before after
idle IME Enter Chromium not sent sent
idle IME Enter WebKit not sent sent
candidate-confirming Enter Chromium not sent not sent
candidate-confirming Enter WebKit not sent not sent

macOS Pinyin can report plain Enter as composing even when no candidate
session is active, which left the composer treating it as IME-owned and
never reaching submit. Send on idle plain Enter when composingRef was false;
keep blocking Enter during an active composition session.

Fixes unslothai#12137
Allow plain Enter when macOS Pinyin marks keyCode 229 without an active
composition, but keep blocking after compositionstart until compositionend
so watchdog-cleared composingRef still re-pins candidate Enter (unslothai#5546).

Update structural IME contract tests to scope the stuck-recovery guard.
@shimmyshimmer

Copy link
Copy Markdown
Member

Confirmed the IME branch in the composer onKeyDown returns before submit even when no composition session is open, which is why plain Enter fails under macOS Pinyin. Will get this reviewed.

@Lyxot Lyxot self-assigned this Oct 1, 2026
@danielhanchen danielhanchen self-assigned this Oct 1, 2026
… idle-IME Enter

WebKit fires compositionend before the committing keydown (keyCode 229), so the
idle-Enter path sent the message when a CJK user confirmed a conversion in Safari
or the macOS desktop app. Treat a 229 keydown within 500 ms of compositionend as
IME-owned, drop the composingRef input that the WebKit commit keydown re-pins,
and reset the open-session flag on blur in the main composer too.
@danielhanchen

Copy link
Copy Markdown
Member

Review record for #12138, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#294.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror f9d3ab47e9 (this PR's 1513f5317)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: f9d3ab47e9

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror f9d3ab47e9 (this PR's 1513f5317).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 1, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 1, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 1, 2026
@danielhanchen
danielhanchen merged commit 05d2b8d into unslothai:main Oct 2, 2026
4 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] macOS Pinyin input method prevents Enter key from sending chat messages

4 participants