fix: skip input rules on the Enter that confirms an IME composition#2879
fix: skip input rules on the Enter that confirms an IME composition#2879greymoth-jp wants to merge 1 commit into
Conversation
|
@greymoth-jp is attempting to deploy a commit to the TypeCell Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis change adds a guard clause in the ChangesIME Enter Guard
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
The input-rules-on-Enter handler in
ExtensionManagerdoes not checkevent.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-rulesregisters a sidecar ProseMirror plugin (inputRulesEnter) whosehandleKeyDowndelegates 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
keydownwithisComposing === true(keyCode229). That event haskey === "Enter"and no modifiers, so it currently reacheshandleTextInput. If the committed text before the cursor matches an input rule, the rule fires in the middle of the composition and the handler returnstrue, which callspreventDefaultand 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
handleKeyDowninNodeSelectionKeyboard(packages/core/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.ts), which checksevent.key === "Enter" && !event.isComposing. The React-side handlers (EditLinkMenuItems,FileRenameButton,FileCaptionButton,EmbedTab, and the suggestion-menu handlers) use the sameisComposingcheck vianativeEvent.Changes
packages/core/src/editor/managers/ExtensionManager/index.ts: return early frominputRulesEnter'shandleKeyDownwhenevent.isComposingis true, so input rules are not run on the composition-commit Enter.Impact
isComposingisfalse, so the handler runs the input rules exactly as before.Testing
main), a composition-commit Enter (isComposing === true) reacheshandleTextInput, and per the existing\s$design a committed prefix such as#matches the heading rule and returnstrue, preventing the commit. With the guard, that path returns early and the composition confirms.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
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 akeydownwithisComposingset if that would help.Summary by CodeRabbit