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/09/16 15:07:30 UTC

[incubator-annotator] branch improve-range-stuff updated: rename stuff

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

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


The following commit(s) were added to refs/heads/improve-range-stuff by this push:
     new bed797e  rename stuff
bed797e is described below

commit bed797e84670e286d55c7253906e093e4ff69357
Author: Gerben <ge...@treora.com>
AuthorDate: Wed Sep 16 17:03:57 2020 +0200

    rename stuff
---
 packages/dom/src/text-iterator.ts    |  9 ++++++++-
 packages/dom/src/text-quote/match.ts | 13 +++----------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/packages/dom/src/text-iterator.ts b/packages/dom/src/text-iterator.ts
index dfc1384..e84ae3c 100644
--- a/packages/dom/src/text-iterator.ts
+++ b/packages/dom/src/text-iterator.ts
@@ -45,8 +45,15 @@ export interface Chunk {
   toString(): string;
 }
 
+export interface ChunkRange<TChunk> {
+  startChunk: TChunk;
+  startIndex: number;
+  endChunk: TChunk;
+  endIndex: number;
+}
+
 // Yields ranges whose start and end nodes are both the *same* Text node.
-export async function* chunkRange(scope: Range): AsyncIterable<TextRange> {
+export async function* rangeToChunks(scope: Range): AsyncIterable<TextRange> {
   const document = ownerDocument(scope);
 
   const iter = document.createNodeIterator(
diff --git a/packages/dom/src/text-quote/match.ts b/packages/dom/src/text-quote/match.ts
index c3fb43d..3ec4b68 100644
--- a/packages/dom/src/text-quote/match.ts
+++ b/packages/dom/src/text-quote/match.ts
@@ -20,7 +20,7 @@
 
 import type { TextQuoteSelector } from '@annotator/selector';
 
-import { chunkRange, Chunk, TextRange } from '../text-iterator';
+import { rangeToTextChunks, Chunk, TextRange, ChunkRange } from '../text-iterator';
 
 export function createTextQuoteSelectorMatcher(
   selector: TextQuoteSelector,
@@ -30,7 +30,7 @@ export function createTextQuoteSelectorMatcher(
     // Turn the scope into a stream of ranges, each wrapping exactly one text node. We wrap it in
     // a range such that the first and last text node can be partially included. Could be changed
     // to e.g. be an object { node: Text, startOffset, endOffset }.
-    const textChunks = chunkRange(scope);
+    const textChunks = rangeToTextChunks(scope);
 
     for await (const abstractMatch of abstractMatcher(textChunks)) {
       const match = document.createRange() as TextRange;
@@ -44,16 +44,9 @@ export function createTextQuoteSelectorMatcher(
   }
 }
 
-interface AbstractRange<TChunk> {
-  startChunk: TChunk;
-  startIndex: number;
-  endChunk: TChunk;
-  endIndex: number;
-}
-
 export function abstractTextQuoteSelectorMatcher(
   selector: TextQuoteSelector,
-): <TChunk extends Chunk>(textChunks: AsyncIterable<TChunk>) => AsyncGenerator<AbstractRange<TChunk>, void, void> {
+): <TChunk extends Chunk>(textChunks: AsyncIterable<TChunk>) => AsyncGenerator<ChunkRange<TChunk>, void, void> {
   return async function* matchAll<TChunk extends Chunk>(textChunks: AsyncIterable<TChunk>) {
     const exact = selector.exact;
     const prefix = selector.prefix || '';