mirror of
https://github.com/heyman/heynote.git
synced 2025-06-20 09:37:50 +02: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 = () => {
|
export const noteBlockExtension = () => {
|
||||||
return [noteBlockWidget(), atomicNoteBlock, blockLayer(), preventFirstBlockFromBeingDeleted]
|
return [
|
||||||
|
noteBlockWidget(),
|
||||||
|
atomicNoteBlock,
|
||||||
|
blockLayer(),
|
||||||
|
preventFirstBlockFromBeingDeleted,
|
||||||
|
preventSelectionBeforeFirstBlock,
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user