Skip to content

Commit

Permalink
fix: prevent RangeError for posToDOMRect, fix #2112
Browse files Browse the repository at this point in the history
  • Loading branch information
philippkuehn committed Oct 31, 2021
1 parent 8b091e8 commit 010418d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/core/src/helpers/posToDOMRect.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 010418d

Please sign in to comment.