• Robert Knight's avatar
    Fix bug that caused double-highlighting of text · c5f246fb
    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
Name
Last commit
Last update
.github Loading commit data...
bin Loading commit data...
dev-server Loading commit data...
docs Loading commit data...
embedding-examples Loading commit data...
images Loading commit data...
scripts Loading commit data...
src Loading commit data...
.babelrc Loading commit data...
.dockerignore Loading commit data...
.eslintignore Loading commit data...
.eslintrc Loading commit data...
.gitignore Loading commit data...
.npmignore Loading commit data...
.npmrc Loading commit data...
.prettierignore Loading commit data...
.prettierrc Loading commit data...
.python-version Loading commit data...
CODE_OF_CONDUCT Loading commit data...
Dockerfile Loading commit data...
Jenkinsfile Loading commit data...
LICENSE Loading commit data...
Makefile Loading commit data...
README.md Loading commit data...
codecov.yml Loading commit data...
gulpfile.js Loading commit data...
package.json Loading commit data...
requirements-dev.in Loading commit data...
tox.ini Loading commit data...
yarn.lock Loading commit data...