fix(list-keymap): prevent selection deletions at the end of list items from joining lists (#5863)
Some checks are pending
build / lint (20) (push) Waiting to run
build / test (20, map[name:Demos/Examples spec:./demos/src/Examples/**/*.spec.{js,ts}]) (push) Waiting to run
build / test (20, map[name:Demos/Experiments spec:./demos/src/Experiments/**/*.spec.{js,ts}]) (push) Waiting to run
build / test (20, map[name:Demos/Extensions spec:./demos/src/Extensions/**/*.spec.{js,ts}]) (push) Waiting to run
build / test (20, map[name:Demos/GuideContent spec:./demos/src/GuideContent/**/*.spec.{js,ts}]) (push) Waiting to run
build / test (20, map[name:Demos/GuideGettingStarted spec:./demos/src/GuideGettingStarted/**/*.spec.{js,ts}]) (push) Waiting to run
build / test (20, map[name:Demos/Marks spec:./demos/src/Marks/**/*.spec.{js,ts}]) (push) Waiting to run
build / test (20, map[name:Demos/Nodes spec:./demos/src/Nodes/**/*.spec.{js,ts}]) (push) Waiting to run
build / test (20, map[name:Integration spec:./tests/cypress/integration/**/*.spec.{js,ts}]) (push) Waiting to run
build / build (20) (push) Blocked by required conditions
Publish / Release (20) (push) Waiting to run

If starting a selection at the end of a list item, then pressing delete, the selected text wasn't being deleted, but instead the following list item was joined to the end.

Now the selected text will be deleted.

Joining will only occur if the selection spans multiple nodes or it's collapsed.
This commit is contained in:
Glenn Allen 2024-11-25 20:36:45 +11:00 committed by GitHub
parent 14681a1906
commit 86250c6e9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
"@tiptap/extension-list-keymap": patch
---
Improve selected text deletion at the end of list items

View File

@ -16,6 +16,15 @@ export const handleDelete = (editor: Editor, name: string) => {
return false
}
// if the selection is not collapsed, or not within a single node
// do nothing and proceed
const { selection } = editor.state
const { $from, $to } = selection
if (!selection.empty && $from.sameParent($to)) {
return false
}
// check if the next node is a list with a deeper depth
if (nextListIsDeeper(name, editor.state)) {
return editor