Skip to content

Commit

Permalink
fix: cmd+a Backspace works
Browse files Browse the repository at this point in the history
Fixes #64
  • Loading branch information
petyosi committed Sep 5, 2023
1 parent fab4e92 commit 8355ad9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/plugins/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,18 @@ export const coreSystem = system((r) => {
KEY_DOWN_COMMAND,
(event) => {
const { keyCode, ctrlKey, metaKey } = event
if (keyCode === 65 && controlOrMeta(metaKey, ctrlKey)) {
let shouldOverride = false

theRootEditor.getEditorState().read(() => {
shouldOverride = $getRoot().getFirstChild()?.getType() === 'frontmatter'
})

if (keyCode === 65 && controlOrMeta(metaKey, ctrlKey) && shouldOverride) {
event.preventDefault()
event.stopImmediatePropagation()
theRootEditor.update(() => {
const root = $getRoot()
const skipFirstChild = root.getFirstChild()?.getType() === 'frontmatter'
root.select(skipFirstChild ? 1 : 0, root.getChildrenSize())

const rootElement = theRootEditor.getRootElement() as HTMLDivElement
window.getSelection()?.selectAllChildren(rootElement)
rootElement.focus({
preventScroll: true
})
Expand All @@ -305,7 +309,7 @@ export const coreSystem = system((r) => {

return false
},
COMMAND_PRIORITY_LOW
COMMAND_PRIORITY_CRITICAL
)
})

Expand Down

0 comments on commit 8355ad9

Please sign in to comment.