Inverse of charOffsetToDomPosition. Walks text nodes in document order;
sums the lengths of every text node preceding node and adds offset.
When node is an element the DOM offset indexes child nodes, not
characters, so it can't simply be added — (overlay, 0) is the start of
the text and (overlay, childNodes.length) its end. That shape is not
exotic: Range.selectNodeContents, which useTextEdit uses for its
select-all caret, produces exactly it. So resolve an element position by
counting the text that precedes the boundary point. A text node can never
contain that point (the container isn't one), so each is wholly before
or wholly after it.
Inverse of
charOffsetToDomPosition. Walks text nodes in document order; sums the lengths of every text node precedingnodeand addsoffset.When
nodeis an element the DOM offset indexes child nodes, not characters, so it can't simply be added —(overlay, 0)is the start of the text and(overlay, childNodes.length)its end. That shape is not exotic:Range.selectNodeContents, whichuseTextEdituses for its select-all caret, produces exactly it. So resolve an element position by counting the text that precedes the boundary point. A text node can never contain that point (the container isn't one), so each is wholly before or wholly after it.