feat(toolbars): support presets for selection and slash menus - #1228
Open
makhnatkin wants to merge 2 commits into
Open
makhnatkin wants to merge 2 commits into
makhnatkin wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/editor/src/extensions/behavior/CommandMenu/handler.ts" line_range="145-158" />
<code_context>
this.clear();
}
+ update(view: EditorView, prevState: EditorState): void {
+ if (
+ this.#view &&
+ contextualToolbarsKey.getState(view.state)?.slash !==
+ contextualToolbarsKey.getState(prevState)?.slash
+ ) {
+ this.#view = view;
+ const needToClose = this.filterActions();
+ if (!this.actions.length || needToClose) {
+ this.#menuRenderItem?.remove();
+ this.#menuRenderItem = undefined;
+ this.closeAutocomplete(view);
+ } else {
+ this.render();
+ }
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** `update` rerenders the command menu whenever the contextual preset changes as long as `#view` was previously set, even after the autocomplete menu has been closed. `clear()` removes the render item but does not clear `#view`, so changing the toolbar preset while no slash menu is open recreates a menu render item from stale command-menu state.
**Triggers:** When a slash menu has been opened and closed, then `toolbarsPreset` changes before another slash menu is opened.
**Suggested fix:** Track whether autocomplete is currently active and return from `update` when it is not, or clear `#view` and the filter state in `clear()`.
</issue_to_address>
Comment on lines
+145
to
+158
| update(view: EditorView, prevState: EditorState): void { | ||
| if ( | ||
| this.#view && | ||
| contextualToolbarsKey.getState(view.state)?.slash !== | ||
| contextualToolbarsKey.getState(prevState)?.slash | ||
| ) { | ||
| this.#view = view; | ||
| const needToClose = this.filterActions(); | ||
| if (!this.actions.length || needToClose) { | ||
| this.#menuRenderItem?.remove(); | ||
| this.#menuRenderItem = undefined; | ||
| this.closeAutocomplete(view); | ||
| } else { | ||
| this.render(); |
There was a problem hiding this comment.
issue (bug_risk): update rerenders the command menu whenever the contextual preset changes as long as #view was previously set, even after the autocomplete menu has been closed. clear() removes the render item but does not clear #view, so changing the toolbar preset while no slash menu is open recreates a menu render item from stale command-menu state.
Triggers: When a slash menu has been opened and closed, then toolbarsPreset changes before another slash menu is opened.
Suggested fix: Track whether autocomplete is currently active and return from update when it is not, or clear #view and the filter state in clear().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Shared configuration for all toolbars (Closes #1226)