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/10/13 20:59:40 UTC
[incubator-annotator] 05/05: Skip empty nodes again when seeking
This is an automated email from the ASF dual-hosted git repository.
gerben pushed a commit to branch import-dom-seek
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git
commit 526a6eeac17e602820f6dedcfb06723bd3acc21a
Author: Gerben <ge...@treora.com>
AuthorDate: Tue Oct 13 22:46:12 2020 +0200
Skip empty nodes again when seeking
---
packages/dom/src/seek.ts | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/packages/dom/src/seek.ts b/packages/dom/src/seek.ts
index c8f77ad..1344dc8 100644
--- a/packages/dom/src/seek.ts
+++ b/packages/dom/src/seek.ts
@@ -56,7 +56,15 @@ export class Seeker {
count += (node as Text).data.length;
}
+ // If there are subsequent nodes, move to ‘before’ the next non-empty
+ // node (or the last node, in case all subsequent nodes are empty).
+ // As this moves from ‘after’ the current node, count is not changed.
if (iter.nextNode()) {
+ node = iter.referenceNode;
+ while (node !== null && (node as Text).data.length === 0) { // node should always be Text now due to the NodeFilter.
+ node = iter.nextNode();
+ }
+ // Note this direction switch stays within the same node.
node = iter.previousNode();
}