Use selection.head when instead of to/from when determining active block, and formatting code

This commit is contained in:
Jonatan Heyman 2023-03-03 01:49:50 +01:00
parent e1fe26b881
commit 2c1e23c9f4
2 changed files with 2 additions and 2 deletions

View File

@ -74,7 +74,7 @@ export const blockState = StateField.define({
export function getActiveNoteBlock(state) { export function getActiveNoteBlock(state) {
// find which block the cursor is in // find which block the cursor is in
const range = state.selection.asSingle().ranges[0] const range = state.selection.asSingle().ranges[0]
return state.facet(blockState).find(block => block.range.from <= range.from && block.range.to >= range.from) return state.facet(blockState).find(block => block.range.from <= range.head && block.range.to >= range.head)
} }
export function getNoteBlockFromPos(state, pos) { export function getNoteBlockFromPos(state, pos) {

View File

@ -28,7 +28,7 @@ export const formatBlockContent = ({ state, dispatch }) => {
return false return false
// get current cursor position // get current cursor position
const cursorPos = state.selection.asSingle().ranges[0].to const cursorPos = state.selection.asSingle().ranges[0].head
// get block content // get block content
const content = state.sliceDoc(block.content.from, block.content.to) const content = state.sliceDoc(block.content.from, block.content.to)