-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add coordsAtPos and posToClientRect helper methods
- Loading branch information
1 parent
cadabd0
commit 8dab614
Showing
3 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { EditorView } from 'prosemirror-view' | ||
import coordsAtPos from './coordsAtPos' | ||
|
||
export default function posToClientRect(view: EditorView, from: number, to: number): ClientRect { | ||
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 | ||
|
||
return { | ||
width, | ||
height, | ||
top, | ||
bottom, | ||
left, | ||
right, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters