Created
December 14, 2016 12:21
-
-
Save Soreine/ee429563cb7b079f7bbfb2f04553add6 to your computer and use it in GitHub Desktop.
Slate relative offset
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
/** | |
* Converts a {key, offset} combination to a single offset relative to | |
* `node`. `key` must be the key of one of the texts inside `node`. | |
*/ | |
function relativeOffset(node, key, offset) { | |
return node | |
.getTexts() | |
.takeUntil(text => text.key === key) | |
.reduce((absOffset, text) => absOffset + text.length) | |
+ offset; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment