You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@annotator.apache.org by ge...@apache.org on 2020/05/22 17:40:02 UTC

[incubator-annotator] 07/09: Fix failing test case

This is an automated email from the ASF dual-hosted git repository.

gerben pushed a commit to branch dom-tests
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git

commit be49aa238fc313141873df3367004dfd5bdb48e9
Author: Gerben <ge...@treora.com>
AuthorDate: Fri May 22 17:59:20 2020 +0200

    Fix failing test case
    
    Our iterator would include text outside the scope’s range but within
    its commonAncestorContainer.
    
    Same mistake is also present in describe.ts; asks for a better approach.
---
 packages/dom/src/text-quote/match.ts | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/packages/dom/src/text-quote/match.ts b/packages/dom/src/text-quote/match.ts
index d5ded88..cc1de71 100644
--- a/packages/dom/src/text-quote/match.ts
+++ b/packages/dom/src/text-quote/match.ts
@@ -36,7 +36,16 @@ export function createTextQuoteSelectorMatcher(selector: TextQuoteSelector): Dom
     const suffix = selector.suffix || '';
     const pattern = prefix + exact + suffix;
 
-    const iter = document.createNodeIterator(root, NodeFilter.SHOW_TEXT);
+    const iter = document.createNodeIterator(
+      root,
+      NodeFilter.SHOW_TEXT,
+      {
+        acceptNode: node =>
+          range.intersectsNode(node)
+            ? NodeFilter.FILTER_ACCEPT
+            : NodeFilter.FILTER_REJECT
+      },
+    );
 
     let fromIndex = 0;
     let referenceNodeIndex = 0;