-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Adjust the splitBlock
command to return false
when it was unsuccessful
#5371
fix: Adjust the splitBlock
command to return false
when it was unsuccessful
#5371
Conversation
🦋 Changeset detectedLatest commit: cc8541a The changes in this PR will be included in the next version bump. This PR includes changesets to release 54 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
if (selection instanceof TextSelection) { | ||
tr.deleteSelection() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry this is not correct, it should only ever manipulate the transaction if dispatch
is true. This would break the behavior of commands being allowed to fail silently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. This made me find another issue, where if the block cannot be split, the selection is erroneously deleted. So i've moved this to only occur when both dispatch
and can
are truthy.
Not sure why/if we'd want to ensureMarks
or scrollIntoView
if we cannot split the block, but that behavior was already present, & i don't see how it breaks anything?
Changes Overview
Fix the
splitBlock
command so that it returnstrue
when it successfully split a block &false
when it does not. Allows for consumers to determine if the command was successful & act accordingly.Implementation Approach
splitBlock
already determined if a split was possible & saved those results to acan
variable. This change returns thecan
variable, both whendispatch
is defined & undefined.Testing Done
I altered the
CustomDocument
example to only allow a single block by settingcontent: heading block
. I then added a custom Enter keyboard shortcut to log ifsplitBlock
returned false. Pushing the enter key anywhere in the document will now log "success".Verification Steps
content: 'block'
on a document. Calleditor.commands.splitBlock()
& ensure it returnsfalse
.content: 'block+'
. Ensure thateditor.commands.splitBlock()
now returnstrue
.Additional Notes
Checklist
Related Issues
Fixes: #5363