diff --git a/packages/editor/src/plugins/list/handlers/listOnBackspace.ts b/packages/editor/src/plugins/list/handlers/listOnBackspace.ts index 74a19cc109..17238b2621 100644 --- a/packages/editor/src/plugins/list/handlers/listOnBackspace.ts +++ b/packages/editor/src/plugins/list/handlers/listOnBackspace.ts @@ -11,24 +11,23 @@ import type { ShortcutHandler } from "../../../core"; import { LIST_ELEMENT_TYPE, LIST_ITEM_ELEMENT_TYPE } from "../listTypes"; import { hasNodeOfType } from "../../../queries/hasNodeOfType"; import { getCurrentBlock } from "../../../queries/getCurrentBlock"; -import { isListItemElement } from "../queries/listElementQueries"; +// This function only has one purpose: to remove a list item when the user presses backspace at the start of a list item. +// Can probably be simplified further. export const listOnBackspace: ShortcutHandler = (editor, event) => { - if (!editor.selection || !hasNodeOfType(editor, LIST_ELEMENT_TYPE)) return false; + if (!editor.selection || !Range.isCollapsed(editor.selection) || !hasNodeOfType(editor, LIST_ELEMENT_TYPE)) + return false; const entry = getCurrentBlock(editor, LIST_ITEM_ELEMENT_TYPE); if (!entry) return false; - const [currentItemNode, currentItemPath] = entry; - if (isListItemElement(currentItemNode) && Range.isCollapsed(editor.selection)) { - // Check that cursor is not expanded. - const [, firstItemNodePath] = editor.node([...currentItemPath, 0]); - // If cursor is placed at start of first item child - if (Point.equals(Range.start(editor.selection), editor.start(firstItemNodePath))) { - event.preventDefault(); - Transforms.liftNodes(editor, { at: currentItemPath }); - return true; - } + const [, currentItemPath] = entry; + // Check that cursor is not expanded. + // If cursor is placed at start of first item child + if (Point.equals(Range.start(editor.selection), editor.start(currentItemPath.concat(0)))) { + event.preventDefault(); + Transforms.liftNodes(editor, { at: currentItemPath }); + return true; } return false; };