Treora commented on issue #112:
URL: 
https://github.com/apache/incubator-annotator/issues/112#issuecomment-868443072


   Can reproduce. The issue is that if the DOM is changed (by 
`highlightRange`/`highlightText`) while the TextQuoteSelector is being matched, 
it can end up finding the quote again and again. (note that the `refinedBy` 
part is not relevant here, the TextQuoteSelector could be passed to 
`createMatcher` directly)
   
   I would like our text matching to be resistant to DOM changes that do not 
modify the text content. I am not sure how easy or hard this may be to achieve. 
If we cannot fix this, it seems unhelpful to return an (async) iterable, and 
we’d better just return an array with the matches.
   
   For now, best is to avoid changing the DOM while running the matcher, and 
first collect the matches in an array. For example, we do this in the demo:
   
   ```
     const matchAll = createMatcher(selector);
     const ranges = [];
   
     for await (const range of matchAll(target)) {
       ranges.push(range);
     }
   
     for (const range of ranges) {
       const removeHighlight = highlightText(range);
       moduleState.cleanupFunctions.push(removeHighlight);
     }
   ```
   
   I see now that I gave the simpler but broken example in the [getting 
started](https://annotator.apache.org/docs/getting-started/) page. I will add 
update and a note!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to