fix(core): setNodeSelection should not clamp pos by Selection.atStart/atEnd (#3091)
Fixes #3090.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { NodeSelection, Selection } from 'prosemirror-state'
|
import { NodeSelection } from 'prosemirror-state'
|
||||||
|
|
||||||
import { RawCommands } from '../types'
|
import { RawCommands } from '../types'
|
||||||
import { minMax } from '../utilities/minMax'
|
import { minMax } from '../utilities/minMax'
|
||||||
@@ -17,10 +17,8 @@ declare module '@tiptap/core' {
|
|||||||
export const setNodeSelection: RawCommands['setNodeSelection'] = position => ({ tr, dispatch }) => {
|
export const setNodeSelection: RawCommands['setNodeSelection'] = position => ({ tr, dispatch }) => {
|
||||||
if (dispatch) {
|
if (dispatch) {
|
||||||
const { doc } = tr
|
const { doc } = tr
|
||||||
const minPos = Selection.atStart(doc).from
|
const from = minMax(position, 0, doc.content.size)
|
||||||
const maxPos = Selection.atEnd(doc).to
|
const selection = NodeSelection.create(doc, from)
|
||||||
const resolvedPos = minMax(position, minPos, maxPos)
|
|
||||||
const selection = NodeSelection.create(doc, resolvedPos)
|
|
||||||
|
|
||||||
tr.setSelection(selection)
|
tr.setSelection(selection)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user