use minMax fo selection commands
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { TextSelection } from 'prosemirror-state'
|
||||
import minMax from '../utilities/minMax'
|
||||
import { Command, RawCommands, Range } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
@@ -14,7 +15,10 @@ declare module '@tiptap/core' {
|
||||
|
||||
export const setTextSelection: RawCommands['setTextSelection'] = range => ({ tr, dispatch }) => {
|
||||
if (dispatch) {
|
||||
const selection = TextSelection.create(tr.doc, range.from, range.to)
|
||||
const { doc } = tr
|
||||
const from = minMax(range.from, 0, doc.content.size)
|
||||
const to = minMax(range.to, 0, doc.content.size)
|
||||
const selection = TextSelection.create(doc, from, to)
|
||||
|
||||
tr.setSelection(selection)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user