mirror of
https://github.com/heyman/heynote.git
synced 2025-01-11 00:18:29 +01:00
Prevent selection before (and within) first note token
This commit is contained in:
parent
b1c6ebfbf0
commit
c0f8bffc84
@ -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,
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user