mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 06:03:22 +08:00
fix: prevent RangeError for posToDOMRect, fix #2112
This commit is contained in:
parent
8b091e8413
commit
010418d0fd
@ -1,8 +1,13 @@
|
||||
import { EditorView } from 'prosemirror-view'
|
||||
import minMax from '../utilities/minMax'
|
||||
|
||||
export default function posToDOMRect(view: EditorView, from: number, to: number): DOMRect {
|
||||
const start = view.coordsAtPos(from)
|
||||
const end = view.coordsAtPos(to, -1)
|
||||
const minPos = 0
|
||||
const maxPos = view.state.doc.content.size
|
||||
const resolvedFrom = minMax(from, minPos, maxPos)
|
||||
const resolvedEnd = minMax(to, minPos, maxPos)
|
||||
const start = view.coordsAtPos(resolvedFrom)
|
||||
const end = view.coordsAtPos(resolvedEnd, -1)
|
||||
const top = Math.min(start.top, end.top)
|
||||
const bottom = Math.max(start.bottom, end.bottom)
|
||||
const left = Math.min(start.left, end.left)
|
||||
|
Loading…
Reference in New Issue
Block a user