From 2c1e23c9f459696d32a7c9c9da005895f3e397ca Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Fri, 3 Mar 2023 01:49:50 +0100 Subject: [PATCH] Use selection.head when instead of to/from when determining active block, and formatting code --- src/editor/block/block.js | 2 +- src/editor/block/format-code.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/editor/block/block.js b/src/editor/block/block.js index 4abd7eb..f3b2cd7 100644 --- a/src/editor/block/block.js +++ b/src/editor/block/block.js @@ -74,7 +74,7 @@ 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.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) { diff --git a/src/editor/block/format-code.js b/src/editor/block/format-code.js index f2ea0f2..8c123ed 100644 --- a/src/editor/block/format-code.js +++ b/src/editor/block/format-code.js @@ -28,7 +28,7 @@ export const formatBlockContent = ({ state, dispatch }) => { return false // get current cursor position - const cursorPos = state.selection.asSingle().ranges[0].to + const cursorPos = state.selection.asSingle().ranges[0].head // get block content const content = state.sliceDoc(block.content.from, block.content.to)