Skip to content

Commit

Permalink
fix: backspace regression
Browse files Browse the repository at this point in the history
  • Loading branch information
petyosi committed Nov 11, 2024
1 parent d14f4f2 commit 0910c73
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/plugins/frontmatter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import {
$getRoot,
$getSelection,
$isRangeSelection,
$isTextNode,
$setSelection,

Check warning on line 18 in src/plugins/frontmatter/index.ts

View workflow job for this annotation

GitHub Actions / Release

'$setSelection' is defined but never used. Allowed unused vars must match /^_/u
COMMAND_PRIORITY_CRITICAL,
ElementNode,
KEY_DOWN_COMMAND,
LexicalEditor
} from 'lexical'
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 0910c73

Please sign in to comment.