refactoring: rename posToClientRect to posToDOMRect

This commit is contained in:
Philipp Kühn
2021-04-16 14:44:10 +02:00
parent c4e0010656
commit 89b72b8608
4 changed files with 18 additions and 10 deletions

View File

@@ -0,0 +1,30 @@
import { EditorView } from 'prosemirror-view'
import coordsAtPos from './coordsAtPos'
export default function posToDOMRect(view: EditorView, from: number, to: number): DOMRect {
const start = coordsAtPos(view, from)
const end = coordsAtPos(view, to, true)
const top = Math.min(start.top, end.top)
const bottom = Math.max(start.bottom, end.bottom)
const left = Math.min(start.left, end.left)
const right = Math.max(start.right, end.right)
const width = right - left
const height = bottom - top
const x = left
const y = top
const data = {
top,
bottom,
left,
right,
width,
height,
x,
y,
}
return {
...data,
toJSON: () => data,
}
}