mirror of
https://github.com/heyman/heynote.git
synced 2024-11-25 17:33:31 +01:00
Prevent search and replace from changing block deklimiters
This commit is contained in:
parent
d59d8fd7e7
commit
e6a6561395
@ -229,8 +229,21 @@ const blockLayer = layer({
|
||||
|
||||
|
||||
const preventFirstBlockFromBeingDeleted = EditorState.changeFilter.of((tr) => {
|
||||
//console.log("change filter!", tr)
|
||||
const protect = []
|
||||
if (!tr.annotations.some(a => a.type === heynoteEvent) && firstBlockDelimiterSize) {
|
||||
return [0, firstBlockDelimiterSize]
|
||||
protect.push(0, firstBlockDelimiterSize)
|
||||
}
|
||||
// if the transaction is a search and replace, we want to protect all block delimiters
|
||||
if (tr.annotations.some(a => a.value === "input.replace" || a.value === "input.replace.all")) {
|
||||
const blocks = tr.startState.facet(blockState)
|
||||
blocks.forEach(block => {
|
||||
protect.push(block.delimiter.from, block.delimiter.to)
|
||||
})
|
||||
//console.log("protected ranges:", protect)
|
||||
}
|
||||
if (protect.length > 0) {
|
||||
return protect
|
||||
}
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user