From 0910c7370364e3b78749410fa1504863ad237805 Mon Sep 17 00:00:00 2001 From: Petyo Ivanov Date: Mon, 11 Nov 2024 08:00:42 +0200 Subject: [PATCH] fix: backspace regression --- src/plugins/frontmatter/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/plugins/frontmatter/index.ts b/src/plugins/frontmatter/index.ts index 95080c1..27942ef 100644 --- a/src/plugins/frontmatter/index.ts +++ b/src/plugins/frontmatter/index.ts @@ -14,8 +14,10 @@ import { $getRoot, $getSelection, $isRangeSelection, + $isTextNode, $setSelection, COMMAND_PRIORITY_CRITICAL, + ElementNode, KEY_DOWN_COMMAND, LexicalEditor } from 'lexical' @@ -107,8 +109,15 @@ export const frontmatterPlugin = realmPlugin({ if ($isRangeSelection(selection)) { if (selection.isCollapsed() && selection.anchor.offset === 0 && selection.focus.offset === 0 && event.key === 'Backspace') { - shouldPrevent = true - event.preventDefault() + let node = selection.getNodes()[0] as ElementNode | null + if ($isTextNode(node)) { + node = node.getParent() + } + const prevSibling = node?.getPreviousSibling() + if ($isFrontmatterNode(prevSibling)) { + shouldPrevent = true + event.preventDefault() + } } else { const firstNode = selection.getNodes()[0] if ($isFrontmatterNode(firstNode)) {