ueberdosis / tiptap

The headless rich text editor framework for web artisans.
https://tiptap.dev
MIT License
27.55k stars 2.29k forks source link

Fix the issue where `can()` check returns `false` even when the command can be executed. #5741

Closed guanriyue closed 4 weeks ago

guanriyue commented 1 month ago

Changes Overview

Fix the issue where can() check returns false even when the command is actually executable.

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 https://github.com/ueberdosis/tiptap/pull/3026 and resolves the issue https://github.com/ueberdosis/tiptap/issues/3025 caused by the clearNodes error.

At the same time, it will also fix issue https://github.com/ueberdosis/tiptap/issues/3229 and issue https://github.com/ueberdosis/tiptap/issues/4057.

————————————————————————————————————————————————————

For more details, please refer to this issue https://github.com/ueberdosis/tiptap/issues/5721.

Testing Done

In the example default editor, add the disabled attribute to the heading and list action buttons. Before the change, if the cursor was positioned 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 be displayed as enabled.

Verification Steps

None.

Additional Notes

Checklist

Related Issues

changeset-bot[bot] commented 1 month ago

⚠️ No Changeset found

Latest commit: 072ef6d3f5de48993ec5541fb199d68ef99d02ab

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

[Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/guanriyue/tiptap/new/fix/can-clearNodes?filename=.changeset/wise-masks-hang.md&value=---%0A%22tiptap-demos%22%3A%20patch%0A%22%40tiptap%2Fcore%22%3A%20patch%0A---%0A%0AFix%20the%20issue%20where%20%60can()%60%20check%20returns%20%60false%60%20even%20when%20the%20command%20can%20be%20executed.%0A)

netlify[bot] commented 1 month ago

Deploy Preview for tiptap-embed ready!

Name Link
Latest commit 072ef6d3f5de48993ec5541fb199d68ef99d02ab
Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/6715be03c730880008f2aac6
Deploy Preview https://deploy-preview-5741--tiptap-embed.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

nperez0111 commented 4 weeks ago

@guanriyue did you mean to close this? I hadn't had the chance to review it

guanriyue commented 4 weeks ago

Yes, I confirm that I want to close this PR. I reevaluated the situation and created a new PR https://github.com/ueberdosis/tiptap/pull/5744, adding corresponding test cases to ensure that the changes are correct.