aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/fg/js/document.js2
-rw-r--r--ext/fg/js/source.js10
-rw-r--r--test/data/html/test-document1.html1
3 files changed, 9 insertions, 4 deletions
diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js
index 6103c7c5..d639bc86 100644
--- a/ext/fg/js/document.js
+++ b/ext/fg/js/document.js
@@ -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 = [];
diff --git a/ext/fg/js/source.js b/ext/fg/js/source.js
index b3119d40..c9d70215 100644
--- a/ext/fg/js/source.js
+++ b/ext/fg/js/source.js
@@ -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;
}
diff --git a/test/data/html/test-document1.html b/test/data/html/test-document1.html
index 0754a314..98a6fb44 100644
--- a/test/data/html/test-document1.html
+++ b/test/data/html/test-document1.html
@@ -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;" />