Skip to content

Fix IME composition Enter key sending message prematurely#31

Merged
Manho merged 2 commits into
Manho:mainfrom
ji3g4m6zo6:fix/ime-enter-submit
Feb 28, 2026
Merged

Fix IME composition Enter key sending message prematurely#31
Manho merged 2 commits into
Manho:mainfrom
ji3g4m6zo6:fix/ime-enter-submit

Conversation

@ji3g4m6zo6
Copy link
Copy Markdown
Contributor

Summary

Fix an issue where pressing Enter during IME composition (e.g. Zhuyin/Bopomofo candidate selection) accidentally triggers message send before typing is finished.

Root cause

unified-input keydown handler sent on Enter without checking IME composition state.

Changes

  • File: multi-panel/multi-panel.js
  • Added composition state tracking:
    • compositionstart -> isInputComposing = true
    • compositionend -> isInputComposing = false
  • Added IME guard before Enter-to-send:
    • isInputComposing || event.isComposing || event.keyCode === 229
  • Keep original behavior for non-IME input:
    • Enter sends
    • Shift+Enter newline

Manual test

  1. Use Zhuyin/Chinese IME in unified input.
  2. Type phonetics to enter composing mode (underlined text).
  3. Press Enter to select candidate.
  4. Verify message is NOT sent during composition.
  5. After composition ends, press Enter again.
  6. Verify message is sent normally.

Copy link
Copy Markdown
Owner

@Manho Manho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! I tested it locally with Zhuyin IME and it works correctly — Enter during composition no longer triggers send. 👍

A couple of suggestions before merging:

1. Move the IME guard inside the Enter check

Currently the guard returns early for all keydown events during IME composition. Right now that's fine since we only handle Enter, but it could silently break future keybindings (e.g. Escape). Suggest narrowing the scope:

inputTextarea.addEventListener('keydown', (e) => {
  if (e.key === 'Enter' && !e.shiftKey) {
    if (isInputComposing || e.isComposing) return;
    e.preventDefault();
    broadcastMessage(inputTextarea.value);
  }
});

2. Consider dropping e.keyCode === 229

Our content scripts (e.g. enter-behavior-chatgpt.js, enter-behavior-claude.js) only use event.isComposing for IME detection. keyCode === 229 is a legacy approach and may false-positive on some Android soft keyboards. For consistency, isInputComposing || e.isComposing should be sufficient.

Other than that, looks good — nice clean fix for a real pain point! 🎉

@ji3g4m6zo6
Copy link
Copy Markdown
Contributor Author

Thanks for the review and suggestions — I’ve updated the PR accordingly.

What I changed

  • Narrowed the IME guard scope to the Enter-to-send path only (no more early return for all keydown events).
  • Removed e.keyCode === 229; now using isInputComposing || e.isComposing.

Verification

Re-tested with Zhuyin IME:

  • Enter during composition selects candidates without sending
  • Enter after composition ends sends normally
  • Shift+Enter still inserts a newline

This keeps non-Enter keydown handling unblocked during composition.
Could you take another look when you have a moment? Thanks!

Copy link
Copy Markdown
Owner

@Manho Manho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the update

@Manho Manho merged commit 8eac82a into Manho:main Feb 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants