Skip to content

fix: Suggestion menu behaviour (BLO-1283, BLO-955) - #2930

Open
matthewlipski wants to merge 3 commits into
mainfrom
multi-character-trigger
Open

fix: Suggestion menu behaviour (BLO-1283, BLO-955)#2930
matthewlipski wants to merge 3 commits into
mainfrom
multi-character-trigger

Conversation

@matthewlipski

@matthewlipski matthewlipski commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes 2 issues r.e. suggestion menus:

  1. Suggestion menus with multi-character triggers don't work properly. There is no prioritization of longer triggers, so given e.g. triggers : and img:, when img: is typed by the user, the : trigger suggestion menu may prioritized with no way to control this behaviour. Also, for longer triggers, checking if they are entered while the text cursor is at the start of the document will throw errors.
  2. Inputting a suggestion menu trigger while a selection is active clears the selection but doesn't open the suggestion menu.

Issue 1 is fixed using basically the same code as proposed in #2918. Issue 2 is fixed by removing a check which ensures the selection is empty before opening a suggestion menu. Given that this was an intentional check we were making, this is more a change in behaviour rather than a bug fix.

Both issues are included in this PR as they touch basically the exact same snippet of code.

Closes #2905
Closes #2090

Rationale

While a suggestion menu's triggerCharacter suggests that a single character should be used, there is not much added complexity to make longer strings work.

As for the suggestion menu opening while a selection is active, this seems to be more in-line with the behaviour of other products.

Changes

  • Removed check for empty selection when determining if a suggestion menu should be opened.
  • Made suggestion menu triggers get ordered by length when determining if a suggestion menu should be opened.
  • Added handling for edge case when a suggestion menu trigger is longer than the text before the cursor, so that we don't attempt to fetch text from an invalid position.
  • Made a small update to docs to note that triggerCharacter also accepts longer strings.

Impact

N/A

Testing

Added unit tests.

Screenshots/Video

N/A

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

N/A

Summary by CodeRabbit

  • New Features

    • Suggestion menus now support multi-character triggers such as img: and ref:.
    • Longer matching triggers take precedence over shorter overlapping triggers.
    • Shorter triggers remain available when a longer trigger does not match the surrounding text.
  • Documentation

    • Updated guidance to explain multi-character suggestion-menu triggers and matching behavior.

@matthewlipski
matthewlipski requested a review from nperez0111 July 29, 2026 13:53
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blocknote Ready Ready Preview Jul 29, 2026 1:53pm
blocknote-website Ready Ready Preview Jul 29, 2026 1:53pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

SuggestionMenu now supports multi-character trigger strings, prioritizes the longest matching trigger, and falls back to shorter triggers when necessary. Documentation and tests cover the updated matching behavior.

Changes

Suggestion trigger matching

Layer / File(s) Summary
Trigger matching implementation
packages/core/src/extensions/SuggestionMenu/SuggestionMenu.ts, docs/content/docs/react/components/suggestion-menus.mdx
Trigger matching now supports multi-character strings, prioritizes longer triggers, and documents the updated behavior.
Multi-character trigger validation
packages/core/src/extensions/SuggestionMenu/SuggestionMenu.test.ts
Tests cover completed triggers, matching after preceding text, longest-trigger precedence, and shorter-trigger fallback.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Poem

A bunny typed img: with cheer,
The menu hopped right over here.
Long triggers lead the way,
Short ones wait for their day.
Tests wiggle whiskers—hooray!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address both linked issues by supporting multi-character triggers and opening the menu with an active selection.
Out of Scope Changes check ✅ Passed The PR stays focused on suggestion menus, tests, and documentation with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed It clearly refers to the suggestion menu behavior changes covered by the PR, even though it is broad.
Description check ✅ Passed The template sections are present and filled out with the key details, tests, checklist, and notes.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch multi-character-trigger

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.

@matthewlipski matthewlipski changed the title fix: Suggestion menu behaviour fix: Suggestion menu behaviour (BLO-1283, BLO-955) Jul 29, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/core/src/extensions/SuggestionMenu/SuggestionMenu.test.ts (1)

143-260: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the remaining trigger-entry paths.

Add regressions for replacing a non-empty selection with a trigger, and for typing when fewer preceding characters exist than the multi-character trigger requires. These are explicit PR objectives but are not exercised here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core/src/extensions/SuggestionMenu/SuggestionMenu.test.ts` around
lines 143 - 260, Extend the SuggestionMenu tests around the existing
multi-character trigger cases to cover replacing a non-empty text selection with
the trigger and typing a multi-character trigger when fewer preceding characters
are available than its length. Assert the expected plugin state and trigger
behavior for each path, using the existing editor setup and cleanup conventions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/core/src/extensions/SuggestionMenu/SuggestionMenu.test.ts`:
- Around line 143-260: Extend the SuggestionMenu tests around the existing
multi-character trigger cases to cover replacing a non-empty text selection with
the trigger and typing a multi-character trigger when fewer preceding characters
are available than its length. Assert the expected plugin state and trigger
behavior for each path, using the existing editor setup and cleanup conventions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cd1bc157-08fc-44b1-bfb6-4ad81af58d4a

📥 Commits

Reviewing files that changed from the base of the PR and between dee7880 and 6b1d1eb.

📒 Files selected for processing (3)
  • docs/content/docs/react/components/suggestion-menus.mdx
  • packages/core/src/extensions/SuggestionMenu/SuggestionMenu.test.ts
  • packages/core/src/extensions/SuggestionMenu/SuggestionMenu.ts

@pkg-pr-new

pkg-pr-new Bot commented Jul 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/@blocknote/ariakit@2930

@blocknote/code-block

npm i https://pkg.pr.new/@blocknote/code-block@2930

@blocknote/core

npm i https://pkg.pr.new/@blocknote/core@2930

@blocknote/mantine

npm i https://pkg.pr.new/@blocknote/mantine@2930

@blocknote/react

npm i https://pkg.pr.new/@blocknote/react@2930

@blocknote/server-util

npm i https://pkg.pr.new/@blocknote/server-util@2930

@blocknote/shadcn

npm i https://pkg.pr.new/@blocknote/shadcn@2930

@blocknote/xl-ai

npm i https://pkg.pr.new/@blocknote/xl-ai@2930

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/@blocknote/xl-docx-exporter@2930

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/@blocknote/xl-email-exporter@2930

@blocknote/xl-multi-column

npm i https://pkg.pr.new/@blocknote/xl-multi-column@2930

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/@blocknote/xl-odt-exporter@2930

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/@blocknote/xl-pdf-exporter@2930

commit: 6b1d1eb

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://TypeCellOS.github.io/BlockNote/pr-preview/pr-2930/

Built to branch gh-pages at 2026-07-29 14:01 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

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 Suggestion menu not opening when text is selected

1 participant