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/11/18 18:59:00 UTC
[incubator-annotator] 01/04: Handle half-characters in
CodePointSeeker.seekToChunk
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 84ae601a32ef278dc4660da6be5a91586950389b
Author: Gerben <ge...@treora.com>
AuthorDate: Wed Nov 18 18:55:18 2020 +0100
Handle half-characters in CodePointSeeker.seekToChunk
---
packages/dom/src/code-point-seeker.ts | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/packages/dom/src/code-point-seeker.ts b/packages/dom/src/code-point-seeker.ts
index b0a95cd..10cb1b1 100644
--- a/packages/dom/src/code-point-seeker.ts
+++ b/packages/dom/src/code-point-seeker.ts
@@ -64,8 +64,21 @@ export class CodePointSeeker<TChunk extends Chunk<string>> implements ChunkSeeke
const oldPosition = this.position;
const oldRawPosition = this.raw.position;
- let result = [...this.raw.readToChunk(target, 0)];
- this.position = this.raw.position >= oldRawPosition
+ let s = this.raw.readToChunk(target, 0);
+
+ const movedForward = this.raw.position >= oldRawPosition;
+
+ if (movedForward && endsWithinCharacter(s)) {
+ this.raw.seekBy(-1);
+ s = s.slice(0, -1);
+ } else if (!movedForward && startsWithinCharacter(s)) {
+ this.raw.seekBy(1);
+ s = s.slice(1);
+ }
+
+ let result = [...s];
+
+ this.position = movedForward
? this.position + result.length
: this.position - result.length;
@@ -86,8 +99,8 @@ export class CodePointSeeker<TChunk extends Chunk<string>> implements ChunkSeeke
this.seekTo(oldPosition);
result = this.readTo(targetPosition);
}
+ return result;
}
- return result;
}
private _readOrSeekTo(read: true, target: number, roundUp?: boolean): string[];