Created
June 24, 2018 10:17
-
-
Save levvsha/c1b20a0a86a7072bd86ff4a923337f2e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| export const getSelectionCoords = (selectionRange) => { | |
| const editorBounds = document.getElementById('editor-container').getBoundingClientRect(); | |
| const rangeBounds = selectionRange.getBoundingClientRect(); | |
| const rangeWidth = rangeBounds.right - rangeBounds.left; | |
| // 107px is width of inline toolbar | |
| const offsetLeft = (rangeBounds.left - editorBounds.left) + (rangeWidth / 2) - (107 / 2); | |
| // 42px is height of inline toolbar | |
| const offsetTop = rangeBounds.top - editorBounds.top - 42; | |
| return { offsetLeft, offsetTop }; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment