From 86250c6e9e760d7af9780cf3ab276b1ec5fedb75 Mon Sep 17 00:00:00 2001 From: Glenn Allen Date: Mon, 25 Nov 2024 20:36:45 +1100 Subject: [PATCH] fix(list-keymap): prevent selection deletions at the end of list items 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. --- .changeset/four-islands-chew.md | 5 +++++ .../src/listHelpers/handleDelete.ts | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 .changeset/four-islands-chew.md diff --git a/.changeset/four-islands-chew.md b/.changeset/four-islands-chew.md new file mode 100644 index 00000000000..74d15a2770a --- /dev/null +++ b/.changeset/four-islands-chew.md @@ -0,0 +1,5 @@ +--- +"@tiptap/extension-list-keymap": patch +--- + +Improve selected text deletion at the end of list items diff --git a/packages/extension-list-keymap/src/listHelpers/handleDelete.ts b/packages/extension-list-keymap/src/listHelpers/handleDelete.ts index 521c5eb5d3a..893b64f98b2 100644 --- a/packages/extension-list-keymap/src/listHelpers/handleDelete.ts +++ b/packages/extension-list-keymap/src/listHelpers/handleDelete.ts @@ -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