fix: check for NodeSelection within posToDOMRect

This commit is contained in:
Philipp Kühn 2021-05-24 08:46:51 +02:00
parent 9e83413967
commit a4ec4ffcfd

View File

@ -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)