Skip to content

Instantly share code, notes, and snippets.

@Soreine
Created December 14, 2016 12:21
Show Gist options
  • Save Soreine/ee429563cb7b079f7bbfb2f04553add6 to your computer and use it in GitHub Desktop.
Save Soreine/ee429563cb7b079f7bbfb2f04553add6 to your computer and use it in GitHub Desktop.
Slate relative offset
/**
* 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