Skip to content

fix(core): prefer longest suggestion menu trigger over shadowing shor…#2918

Open
Gxrvish wants to merge 1 commit into
TypeCellOS:mainfrom
Gxrvish:feat-support-colon-multicharacter-trigger
Open

fix(core): prefer longest suggestion menu trigger over shadowing shor…#2918
Gxrvish wants to merge 1 commit into
TypeCellOS:mainfrom
Gxrvish:feat-support-colon-multicharacter-trigger

Conversation

@Gxrvish

@Gxrvish Gxrvish commented Jul 25, 2026

Copy link
Copy Markdown

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

SuggestionMenuController with triggerCharacter="img:" never fired. The default emoji picker registers :, and handleTextInput matched the first trigger in insertion order — so the single-char : always won and consumed the input before img: was ever checked. img# (no competing trigger) and : alone both worked, which masked the bug.

Changes

  • Sort candidate triggers by length descending in handleTextInput so the most specific (longest) trigger matches first.
  • Fix an off-by-one in the multi-character prefix lookup: from - triggerChar.length grabbed one extra char, so a trigger preceded by other text on the same line (e.g. hello img:) never matched. Now from - (triggerChar.length - 1).

Impact

  • Scoped to @blocknote/core SuggestionMenu.handleTextInput.
  • Multi-char triggers that collide on their final char with a shorter trigger now resolve to the longer one.
  • Single-char triggers and programmatic menu opening are unaffected (single-char path unchanged; sort is stable for equal lengths).

Testing

  • Added 2 unit tests in SuggestionMenu.test.ts:
    • img: preferred over a : trigger registered first (shadowing case).
    • img: matches mid-line (hello img + :), covering the off-by-one fix.
  • Verified both new tests fail on unfixed source and pass with the fix.
  • pnpm lint (full, type-aware) clean.
  • Pre-existing unrelated failures on this machine: chatHandlers.test.ts (needs Node 22 iterator helpers; running Node 20) and htmlBlocks.test.ts (needs LLM provider keys). Neither touches this change.

Screenshots/Video

N/A — non-visual logic fix.

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved suggestion menu matching so longer, multi-character triggers take precedence over shorter triggers.
    • Multi-character triggers now work correctly when typed after existing text within a paragraph.
    • Prevented shorter triggers from opening the wrong suggestion menu.

…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.
@vercel

vercel Bot commented Jul 25, 2026

Copy link
Copy Markdown

@Gxrvish 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 Jul 25, 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 Plus

Run ID: 47df1ec0-24fc-4d88-862f-0d51c3d04bc8

📥 Commits

Reviewing files that changed from the base of the PR and between dee7880 and 2e142e2.

📒 Files selected for processing (2)
  • packages/core/src/extensions/SuggestionMenu/SuggestionMenu.test.ts
  • packages/core/src/extensions/SuggestionMenu/SuggestionMenu.ts

📝 Walkthrough

Walkthrough

SuggestionMenu 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.

Changes

Suggestion trigger matching

Layer / File(s) Summary
Trigger ordering and snippet matching
packages/core/src/extensions/SuggestionMenu/SuggestionMenu.ts, packages/core/src/extensions/SuggestionMenu/SuggestionMenu.test.ts
handleTextInput prioritizes longer triggers, adjusts multi-character snippet extraction, and adds tests for overlapping and mid-line triggers.

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
Loading

Poem

I’m a rabbit, hopping bright,
Longer triggers win the night.
Mid-line paths now bloom anew,
Tests confirm the menu’s cue.
Nibble, type, and suggestions fly!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: preferring the longest suggestion trigger over a shorter shadowing trigger.
Description check ✅ Passed The description includes the required sections and covers summary, rationale, changes, impact, testing, screenshots, and checklist.
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.

@Gxrvish

Gxrvish commented Jul 25, 2026

Copy link
Copy Markdown
Author

@YousefED Can you please have a look!!
Thanks!!

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.

: is not supported on multi-character trigger for suggestion menus

1 participant