fix(core): prefer longest suggestion menu trigger over shadowing shor…#2918
fix(core): prefer longest suggestion menu trigger over shadowing shor…#2918Gxrvish wants to merge 1 commit into
Conversation
…ter one A multi-character trigger like 'img:' never opened because the default single-character emoji ':' menu matched first and shadowed it. handleTextInput looped registered menus in insertion order and returned on the first match, so the shorter trigger always won. Sort candidate triggers by length descending so the most specific trigger wins. Also fix an off-by-one in the multi-character prefix lookup (`from - length` grabbed one extra char), which broke matching when the trigger was preceded by other text on the same line.
|
@Gxrvish 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 Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughSuggestionMenu now checks longer trigger strings before shorter ones and correctly constructs multi-character trigger snippets, including when triggers occur mid-line. Tests cover trigger shadowing and mid-line activation. ChangesSuggestion trigger matching
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant ProseMirrorEditor
participant handleTextInput
participant orderedMenus
participant SuggestionMenuState
ProseMirrorEditor->>handleTextInput: Insert trigger text
handleTextInput->>orderedMenus: Sort triggers by length
orderedMenus-->>handleTextInput: Longest matching trigger
handleTextInput->>SuggestionMenuState: Activate matched menu
Poem
🚥 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 |
|
@YousefED Can you please have a look!! |
Summary
Fix multi-character suggestion menu triggers (e.g.
img:) that never opened when a shorter registered trigger (e.g. the default emoji:) shadowed them. Fixes #2905.Rationale
SuggestionMenuControllerwithtriggerCharacter="img:"never fired. The default emoji picker registers:, andhandleTextInputmatched the first trigger in insertion order — so the single-char:always won and consumed the input beforeimg:was ever checked.img#(no competing trigger) and:alone both worked, which masked the bug.Changes
handleTextInputso the most specific (longest) trigger matches first.from - triggerChar.lengthgrabbed one extra char, so a trigger preceded by other text on the same line (e.g.hello img:) never matched. Nowfrom - (triggerChar.length - 1).Impact
@blocknote/coreSuggestionMenu.handleTextInput.Testing
SuggestionMenu.test.ts:img:preferred over a:trigger registered first (shadowing case).img:matches mid-line (hello img+:), covering the off-by-one fix.pnpm lint(full, type-aware) clean.chatHandlers.test.ts(needs Node 22 iterator helpers; running Node 20) andhtmlBlocks.test.ts(needs LLM provider keys). Neither touches this change.Screenshots/Video
N/A — non-visual logic fix.
Checklist
Summary by CodeRabbit