fix: improve calculation for min/max positions in selections, fix #1588
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { NodeSelection } from 'prosemirror-state'
|
||||
import { Selection, NodeSelection } from 'prosemirror-state'
|
||||
import minMax from '../utilities/minMax'
|
||||
import { RawCommands } from '../types'
|
||||
|
||||
@@ -16,8 +16,10 @@ declare module '@tiptap/core' {
|
||||
export const setNodeSelection: RawCommands['setNodeSelection'] = position => ({ tr, dispatch }) => {
|
||||
if (dispatch) {
|
||||
const { doc } = tr
|
||||
const from = minMax(position, 0, doc.content.size)
|
||||
const selection = NodeSelection.create(doc, from)
|
||||
const minPos = Selection.atStart(doc).from
|
||||
const maxPos = Selection.atEnd(doc).to
|
||||
const resolvedPos = minMax(position, minPos, maxPos)
|
||||
const selection = NodeSelection.create(doc, resolvedPos)
|
||||
|
||||
tr.setSelection(selection)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user