Skip to content

fix: skip input rules on the Enter that confirms an IME composition#2879

Open
greymoth-jp wants to merge 1 commit into
TypeCellOS:mainfrom
greymoth-jp:fix/input-rules-ime-composition-enter
Open

fix: skip input rules on the Enter that confirms an IME composition#2879
greymoth-jp wants to merge 1 commit into
TypeCellOS:mainfrom
greymoth-jp:fix/input-rules-ime-composition-enter

Conversation

@greymoth-jp

@greymoth-jp greymoth-jp commented Jun 30, 2026

Copy link
Copy Markdown

Summary

The input-rules-on-Enter handler in ExtensionManager does not check event.isComposing, so it also runs on the Enter that confirms an IME composition. This adds the same guard the editor's other Enter handlers already use.

Rationale

blocknote-input-rules registers a sidecar ProseMirror plugin (inputRulesEnter) whose handleKeyDown delegates to the input-rules plugin with a synthetic "\n", so that any rule whose regex matches \s$ also fires on Enter (as the comment in that file explains).

On the Enter that commits an IME composition (for example, selecting a kanji candidate after typing hiragana), the browser fires a keydown with isComposing === true (keyCode 229). That event has key === "Enter" and no modifiers, so it currently reaches handleTextInput. If the committed text before the cursor matches an input rule, the rule fires in the middle of the composition and the handler returns true, which calls preventDefault and disrupts the commit.

Example: type # (no trailing space), switch to a Japanese IME, type some hiragana, then press Enter to confirm a candidate. The # plus the synthetic "\n" matches the heading rule, so the block is turned into a heading and the Enter is swallowed instead of confirming the composition.

The editor's other Enter handlers already guard against this. The closest one is the sibling ProseMirror handleKeyDown in NodeSelectionKeyboard (packages/core/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.ts), which checks event.key === "Enter" && !event.isComposing. The React-side handlers (EditLinkMenuItems, FileRenameButton, FileCaptionButton, EmbedTab, and the suggestion-menu handlers) use the same isComposing check via nativeEvent.

Changes

  • packages/core/src/editor/managers/ExtensionManager/index.ts: return early from inputRulesEnter's handleKeyDown when event.isComposing is true, so input rules are not run on the composition-commit Enter.

Impact

  • A normal Enter is unchanged: isComposing is false, so the handler runs the input rules exactly as before.
  • The composition-commit Enter now falls through to confirm the composition instead of triggering an input rule.
  • No public API change. One guard, consistent with the existing handlers.

Testing

  • Verified by reading the code in both directions. With the guard removed (current main), a composition-commit Enter (isComposing === true) reaches handleTextInput, and per the existing \s$ design a committed prefix such as # matches the heading rule and returns true, preventing the commit. With the guard, that path returns early and the composition confirms.
  • A normal Enter (isComposing === false) takes the identical path as before, so the existing input-rule unit tests are unaffected. I did not run the full local suite for this change.

Checklist

  • Code follows the project's coding standards.
  • Unit tests covering the new feature have been added.
  • All existing tests pass.
  • The documentation has been updated to reflect the new feature

Additional Notes

This mirrors the convention used across the other Enter handlers; the cited sibling is NodeSelectionKeyboard. Happy to add a unit test that dispatches a keydown with isComposing set if that would help.

Summary by CodeRabbit

  • Bug Fixes
    • Enter key behavior during IME text composition now avoids triggering input rules, preventing unintended actions while typing with an input method editor.
    • Plain Enter and modifier-key handling remains unchanged outside of composition mode.

@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

@greymoth-jp is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 82a01d05-8c27-4676-bf4d-ba8e5f97c24c

📥 Commits

Reviewing files that changed from the base of the PR and between 3094559 and 4413534.

📒 Files selected for processing (1)
  • packages/core/src/editor/managers/ExtensionManager/index.ts

📝 Walkthrough

Walkthrough

This change adds a guard clause in the inputRulesEnter ProseMirror plugin's handleKeyDown function within ExtensionManager. It checks for event.isComposing and returns early to skip input rule triggering when Enter is pressed during IME composition.

Changes

IME Enter Guard

Layer / File(s) Summary
IME composition check in Enter handler
packages/core/src/editor/managers/ExtensionManager/index.ts
handleKeyDown now returns false early when event.isComposing is true during an Enter keydown, preventing input rules from firing mid-IME-composition.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested reviewers

  • matthewlipski

A rabbit types with careful paws,
Mid-composition, Enter pauses,
No rules shall fire, no text shall jump,
While IME letters form their clump,
A tiny guard, a quiet save —
Hop hop hooray, the input's safe! 🐰⌨️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: skipping input rules on IME composition-commit Enter.
Description check ✅ Passed The description follows the template well and includes summary, rationale, changes, impact, testing, checklist, and notes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant