feat(EditorSuggestionMenu): expose suggestion matching options#6234
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a new optional Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/runtime/composables/useEditorMenu.ts`:
- Around line 68-71: The suggestion spread currently allows options.suggestion
to override core fields (pluginKey, editor, char) which can break plugin state;
update the construction around options.suggestion (where suggestion?:
Partial<SuggestionOptions> is used and options.suggestion is spread) so that
pluginKey, editor and char are applied after spreading user options OR
explicitly omit those keys from the spread (i.e., create a sanitizedSuggestion =
{ ...options.suggestion } without pluginKey/editor/char) and then build the
final suggestion object using pluginKeyInstance/pluginKey/editor/char last to
ensure the core values always take precedence.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 709ec4e6-dd63-4a8c-bfb2-910d23119493
📒 Files selected for processing (5)
CHANGELOG.mddocs/content/docs/2.components/editor-suggestion-menu.mdsrc/runtime/components/EditorSuggestionMenu.vuesrc/runtime/composables/useEditorMenu.tstest/composables/useEditorMenu.spec.ts
commit: |
howwohmm
left a comment
There was a problem hiding this comment.
nice addition — exposing TipTap's suggestion matching options is useful for custom slash commands.
one thing worth watching: the spread order in the suggestion config means options.suggestion could accidentally override pluginKey or editor since it's spread after those positional keys. a consumer passing suggestion: { pluginKey: ... } would silently replace the internal plugin key.
safest fix would be to destructure and omit the dangerous keys before spreading:
const { pluginKey: _pk, editor: _ed, char: _ch, ...safeSuggestion } = options.suggestion || {}or move pluginKey, editor, and char after the spread so they always win. either way it's a one-line guard against a subtle footgun.
|
I pushed the fix! User provided suggestion options are now applied first, and internal plugin fields are set after, cannot be overridden. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/composables/useEditorMenu.spec.ts`:
- Around line 62-69: The helper getSuggestionConfig currently only checks that
suggestionMock.mock.calls has at least one entry; change it to enforce exactly
one call by validating suggestionMock.mock.calls.length === 1 (throw an Error if
length !== 1) before extracting the config, so getSuggestionConfig reliably
fails when Suggestion is called zero or multiple times; keep references to
suggestionMock.mock.calls and the getSuggestionConfig function when making the
change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c84e9a0e-9826-49fe-8376-f22be811c0c2
📒 Files selected for processing (3)
docs/content/docs/2.components/editor-emoji-menu.mddocs/content/docs/2.components/editor-mention-menu.mdtest/composables/useEditorMenu.spec.ts
✅ Files skipped from review due to trivial changes (2)
- docs/content/docs/2.components/editor-emoji-menu.md
- docs/content/docs/2.components/editor-mention-menu.md
🔗 Linked issue
Resolves #6233
❓ Type of change
📚 Description
This PR exposes TipTap suggestion matching options on
UEditorSuggestionMenuso users can customize how trigger characters are matched.The main change is adding a new optional
suggestion?: Partial<SuggestionOptions>prop toUEditorSuggestionMenuand threading it throughEditorMenuOptionsinto the internal TipTapSuggestion(...)configuration.This allows opt-in use cases such as setting
allowedPrefixes: nullso a:trigger can open directly after/or letters, instead of only after whitespace.The implementation preserves existing behavior.
This PR also includes:
suggestionis omittedEditorSuggestionMenupage📝 Checklist