Skip to content

Commit

Permalink
fix: select all with last decorator node
Browse files Browse the repository at this point in the history
  • Loading branch information
petyosi committed Sep 9, 2023
1 parent 137ba12 commit 175c3f8
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/plugins/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
$getRoot,
$getSelection,
$insertNodes,
$isDecoratorNode,
$isRangeSelection,
$isRootOrShadowRoot,
BLUR_COMMAND,
Expand Down Expand Up @@ -288,23 +289,25 @@ export const coreSystem = system((r) => {
KEY_DOWN_COMMAND,
(event) => {
const { keyCode, ctrlKey, metaKey } = event
let shouldOverride = false
if (keyCode === 65 && controlOrMeta(metaKey, ctrlKey)) {
let shouldOverride = false

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

if (keyCode === 65 && controlOrMeta(metaKey, ctrlKey) && shouldOverride) {
event.preventDefault()
event.stopImmediatePropagation()
theRootEditor.update(() => {
const rootElement = theRootEditor.getRootElement() as HTMLDivElement
window.getSelection()?.selectAllChildren(rootElement)
rootElement.focus({
preventScroll: true
if (shouldOverride) {
event.preventDefault()
event.stopImmediatePropagation()
theRootEditor.update(() => {
const rootElement = theRootEditor.getRootElement() as HTMLDivElement
window.getSelection()?.selectAllChildren(rootElement)
rootElement.focus({
preventScroll: true
})
})
})
return true
return true
}
}

return false
Expand Down

0 comments on commit 175c3f8

Please sign in to comment.