From 88371561bbb564c9c94a6ebcfdc44fbf0fbeeb25 Mon Sep 17 00:00:00 2001 From: Juraj Garaj Date: Thu, 7 Nov 2024 09:21:19 +0100 Subject: [PATCH] fix(list-keymap): early exit when selection is not collapsed (#5810) --- .changeset/chatty-monkeys-hear.md | 5 +++++ .../src/listHelpers/handleBackspace.ts | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 .changeset/chatty-monkeys-hear.md diff --git a/.changeset/chatty-monkeys-hear.md b/.changeset/chatty-monkeys-hear.md new file mode 100644 index 000000000..8f8d01daf --- /dev/null +++ b/.changeset/chatty-monkeys-hear.md @@ -0,0 +1,5 @@ +--- +"@tiptap/extension-list-keymap": patch +--- + +Fix backspace behavior when selection is not collapsed diff --git a/packages/extension-list-keymap/src/listHelpers/handleBackspace.ts b/packages/extension-list-keymap/src/listHelpers/handleBackspace.ts index e1fc012ce..506347f31 100644 --- a/packages/extension-list-keymap/src/listHelpers/handleBackspace.ts +++ b/packages/extension-list-keymap/src/listHelpers/handleBackspace.ts @@ -12,6 +12,12 @@ export const handleBackspace = (editor: Editor, name: string, parentListTypes: s return true } + // if the selection is not collapsed + // we can rely on the default backspace behavior + if (editor.state.selection.from !== editor.state.selection.to) { + return false + } + // if the current item is NOT inside a list item & // the previous item is a list (orderedList or bulletList) // move the cursor into the list and delete the current item