Phenomenon
Selecting across nested block structures causes the Selection API to report inconsistent boundaries. Visually, the highlight looks correct, but programmatically, the anchorNode or focusNode can jump to the parent container instead of the leaf text node.
Reproduction Steps
- Create two paragraphs:
<p>One</p><p>Two</p>. - Select from the middle of “One” to the middle of “Two”.
- Call
window.getSelection().getRangeAt(0). - Observe that
startContainermight be the parentdivinstead of the first<p>.
Observed Behavior
Edge/Chrome engines sometimes optimize range calculations by collapsing boundaries to the nearest common block, losing the fine-grained text offset.