Fixed issue where can() returned false when the command was executable #5744
+39
−5
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.
Changes Overview
Fix the issue where can() check returns false even when the command is actually executable. And added cypress test cases.
Implementation Approach
When chainCommand is executed, multiple commands are run sequentially. The editor state used by later commands may depend on the preceding commands. Therefore, when executing can(), createChain must ensure that shouldDispatch is true to prevent skipping operations on tr.
This fix effectively reverts the code changes from the pull request #3026 and resolves the issue #3025 caused by the clearNodes error.
At the same time, it will also fix issue #3229 and issue #4057.
For more details, please refer to this issue #5721.
Testing Done
First, add the disabled attribute to the heading and list action buttons in the example default editor.
Before the fix, if the selection was on a heading node, the list action buttons would remain disabled, even though the commands were actually available. After the change, the list action buttons will appear enabled.
Additionally, corresponding Cypress test cases have been added.
Verification Steps
Access the default example editor at https://tiptap.dev/docs/examples/basics/default-text-editor or by executing cypress test
Additional Notes
Checklist
Related Issues