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


The following commit(s) were added to refs/heads/import-dom-seek by this push:
     new 00679b1  WIP further steps on describe text quote
00679b1 is described below

commit 00679b19929a8f745ce67977ffcfe12237b39f21
Author: Gerben <[email protected]>
AuthorDate: Wed Nov 11 18:47:47 2020 +0100

    WIP further steps on describe text quote
---
 packages/dom/src/chunker.ts             |  2 ++
 packages/dom/src/seek.ts                | 15 +++++++++------
 packages/dom/src/text-quote/describe.ts |  1 +
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/packages/dom/src/chunker.ts b/packages/dom/src/chunker.ts
index 7209d7a..5926290 100644
--- a/packages/dom/src/chunker.ts
+++ b/packages/dom/src/chunker.ts
@@ -56,6 +56,8 @@ export interface Chunker<TChunk extends Chunk<any>> {
   // currentChunk is null only if it contains no chunks at all.
   readonly currentChunk: TChunk | null;
 
+  setCurrentChunk?(target: TChunk): void;
+
   // Move currentChunk to the chunk following it, and return that chunk.
   // If there are no chunks following it, keep currentChunk unchanged and 
return null.
   nextChunk(): TChunk | null;
diff --git a/packages/dom/src/seek.ts b/packages/dom/src/seek.ts
index cd314b6..37756c9 100644
--- a/packages/dom/src/seek.ts
+++ b/packages/dom/src/seek.ts
@@ -18,14 +18,12 @@
  * under the License.
  */
 
-import { Chunk, TextNodeChunker, PartialTextNode, chunkEquals } from 
"./chunker";
+import { Chunk, Chunker, TextNodeChunker, PartialTextNode, chunkEquals } from 
"./chunker";
 
 const E_END = 'Iterator exhausted before seek ended.';
 
-export interface NonEmptyChunker<TChunk extends Chunk<any>> {
+export interface NonEmptyChunker<TChunk extends Chunk<any>> extends 
Chunker<TChunk> {
   readonly currentChunk: TChunk;
-  nextChunk(): TChunk | null;
-  previousChunk(): TChunk | null;
 }
 
 export interface BoundaryPointer<T extends any> {
@@ -78,7 +76,12 @@ export class TextSeeker<TChunk extends Chunk<string>> 
implements Seeker<string>
   }
 
   seekToChunk(target: TChunk, offset: number = 0) {
-    this._readOrSeekToChunk(false, target, offset);
+    if (this.chunker.setCurrentChunk) {
+      this.chunker.setCurrentChunk(target);
+      this.offsetInChunk = offset;
+    } else {
+      this._readOrSeekToChunk(false, target, offset);
+    }
   }
 
   readToChunk(target: TChunk, offset: number = 0): string {
@@ -88,7 +91,7 @@ export class TextSeeker<TChunk extends Chunk<string>> 
implements Seeker<string>
   private _readOrSeekToChunk(read: true, target: TChunk, offset?: number): 
string
   private _readOrSeekToChunk(read: false, target: TChunk, offset?: number): 
void
   private _readOrSeekToChunk(read: boolean, target: TChunk, offset: number = 
0): string {
-    // XXX We have no way of knowing whether a chunk will follow or precedes 
the current chunk; we assume it follows.
+    // XXX We have no way of knowing whether a chunk follows or precedes the 
current chunk; we assume it follows.
     let result = '';
     // This will throw a RangeError if we reach the end without encountering 
the target chunk.
     while (!chunkEquals(this.currentChunk, target)) {
diff --git a/packages/dom/src/text-quote/describe.ts 
b/packages/dom/src/text-quote/describe.ts
index cbad0c3..2afe0e2 100644
--- a/packages/dom/src/text-quote/describe.ts
+++ b/packages/dom/src/text-quote/describe.ts
@@ -90,6 +90,7 @@ async function abstractDescribeTextQuote<TChunk extends 
Chunk<string>>(
     const seeker2 = new TextSeeker(scope as NonEmptyChunker<TChunk>); // TODO 
must clone scope.
 
     // Count how many characters we’d need as a prefix to disqualify this 
match.
+    // chunker1.currentChunk = target.startChunk;
     seeker1.seekToChunk(target.startChunk, target.startIndex);
     seeker2.seekToChunk(unintendedMatch.startChunk, 
unintendedMatch.startIndex);
     let sufficientPrefix: string | undefined = prefix;

Reply via email to