Change getActiveNoteBlock and getNoteBlockFromPos so that they return a block even if the cursor is hidden within a separator. Shouldn't happen, but this should make it more robust.

This commit is contained in:
Jonatan Heyman 2023-01-24 18:04:07 +01:00
parent 751dfa0a73
commit b44b47991b

View File

@ -38,6 +38,10 @@ function getBlocks(state) {
from: type.from,
to: type.to,
},
range: {
from: type.node.from,
to: contentNode.to,
},
})
return false;
}
@ -69,11 +73,11 @@ export const blockState = StateField.define({
export function getActiveNoteBlock(state) {
// find which block the cursor is in
const range = state.selection.asSingle().ranges[0]
return state.facet(blockState).find(block => block.content.from <= range.from && block.content.to >= range.from)
return state.facet(blockState).find(block => block.range.from <= range.from && block.range.to >= range.from)
}
export function getNoteBlockFromPos(state, pos) {
return state.facet(blockState).find(block => block.content.from <= pos && block.content.to >= pos)
return state.facet(blockState).find(block => block.range.from <= pos && block.range.to >= pos)
}