Text scanning update (#507)

* Fix unity test missing a parameter

* Update docSentenceExtract to not rescan content
This commit is contained in:
toasted-nutbread 2020-05-06 19:34:32 -04:00 committed by GitHub
parent f7df6254d6
commit d6ae322961
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 4 deletions

View File

@ -159,7 +159,7 @@ function docSentenceExtract(source, extent) {
const sourceLocal = source.clone();
const position = sourceLocal.setStartOffset(extent);
sourceLocal.setEndOffset(position + extent);
sourceLocal.setEndOffset(extent * 2 - position, true);
const content = sourceLocal.text();
let quoteStack = [];

View File

@ -46,10 +46,14 @@ class TextSourceRange {
return this.content;
}
setEndOffset(length) {
const state = TextSourceRange.seekForward(this.range.startContainer, this.range.startOffset, length);
setEndOffset(length, fromEnd=false) {
const state = (
fromEnd ?
TextSourceRange.seekForward(this.range.endContainer, this.range.endOffset, length) :
TextSourceRange.seekForward(this.range.startContainer, this.range.startOffset, length)
);
this.range.setEnd(state.node, state.offset);
this.content = state.content;
this.content = (fromEnd ? this.content + state.content : state.content);
return length - state.remainder;
}

View File

@ -103,6 +103,7 @@
data-end-node-selector="img"
data-end-offset="0"
data-result-type="TextSourceElement"
data-sentence-extent="100"
data-sentence="よみちゃん"
>
<img src="data:image/gif;base64,R0lGODdhBwAHAIABAAAAAP///ywAAAAABwAHAAACDIRvEaC32FpCbEkKCgA7" alt="よみちゃん" title="よみちゃん" style="width: 70px; height: 70px; image-rendering: crisp-edges; image-rendering: pixelated; display: block;" />