Prevent selection before (and within) first note token

This commit is contained in:
Jonatan Heyman 2022-12-28 15:28:40 +01:00
parent b1c6ebfbf0
commit c0f8bffc84
1 changed files with 25 additions and 1 deletions

View File

@ -173,6 +173,30 @@ const preventFirstBlockFromBeingDeleted = EditorState.changeFilter.of((tr) => {
}
})
/**
* Transaction filter to prevent the selection from being before the first block
*/
const preventSelectionBeforeFirstBlock = EditorState.transactionFilter.of((tr) => {
//console.log("transaction:", tr)
tr?.selection?.ranges.forEach(range => {
// change the selection to after the first block if the transaction sets the selection before the first block
if (range && range.from < 10) {
range.from = 10
}
if (range && range.to < 10) {
range.to = 10
}
})
return tr
})
export const noteBlockExtension = () => {
return [noteBlockWidget(), atomicNoteBlock, blockLayer(), preventFirstBlockFromBeingDeleted]
return [
noteBlockWidget(),
atomicNoteBlock,
blockLayer(),
preventFirstBlockFromBeingDeleted,
preventSelectionBeforeFirstBlock,
]
}