I am working with a real time editor and need to find all text nodes that are inside the range a user has selected.
Example (the “|” marks the selection range start and end point):
<p>Here starts the |selection.</p>
<p>This is fully in the range.</p>
<p>This only |partial.</p>
How do i find all those nodes? (i do not want to find the textnode “Here” in case there is more than one textnodes in the first paragraph! (there could be several!))
Rangy (disclosure: written by me) does this for you:
Otherwise, I’d suggest traversing the DOM of the range’s
commonAncestorContainerand for each text node encountered, check whether it overlaps the range by creating a range for the text node (usingselectNode()) and using itscompareBoundaryPoints()method to compare it to the selection range.