Skip to content

Commit

Permalink
fix: check for NodeSelection within posToDOMRect
Browse files Browse the repository at this point in the history
  • Loading branch information
philippkuehn committed May 24, 2021
1 parent 9e83413 commit a4ec4ff
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/core/src/helpers/posToDOMRect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import isNodeSelection from './isNodeSelection'
import { EditorView } from 'prosemirror-view'
import coordsAtPos from './coordsAtPos'

export default function posToDOMRect(view: EditorView, from: number, to: number): DOMRect {
if (isNodeSelection(view.state.selection)) {
const node = view.nodeDOM(from) as HTMLElement

if (node && node.getBoundingClientRect) {
return node.getBoundingClientRect()
}
}

const start = coordsAtPos(view, from)
const end = coordsAtPos(view, to, true)
const top = Math.min(start.top, end.top)
Expand Down

0 comments on commit a4ec4ff

Please sign in to comment.