Skip to content

Commit

Permalink
fix(list-keymap): prevent selection deletions at the end of list item…
Browse files Browse the repository at this point in the history
…s from joining lists (#5863)

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.
  • Loading branch information
glenn-allen authored Nov 25, 2024
1 parent 14681a1 commit 86250c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-islands-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tiptap/extension-list-keymap": patch
---

Improve selected text deletion at the end of list items
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 86250c6

Please sign in to comment.