-
Robert Knight authored
Fix a bug that could cause pieces of text to be highlighted twice rather than once. For this bug to occur: 1. The anchored range had to start in the middle of a text node 2. The anchored range had to end _after_ the text node, so that the range's `commonAncestorContainer` property pointed to an ancestor of the text node In this scenario, the `wholeTextNodesInRange` function would split the text node where the range started and add the piece on the right-hand side of the split to the list of text nodes to wrap in highlight elements. The `forEachNodeInRange` iterator would then visit the right-hand text node a _second_ time because it is the _next node_ it its iteration order. This resulted in the text node being added twice to the `textNodes` list returned by `wholeTextNodesInRange`. To resolve this, rewrite the loop in `wholeTextNodesInRange` so that it visits each text node in the range only once, even if the node is split mid-iteration. In doing so a small optimization was made by setting the `NodeIterator`'s filter to `NodeFilter.SHOW_TEXT` in order to skip any non text nodes.
c5f246fb