diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-04-08 18:04:37 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-04-08 18:04:37 -0700 |
commit | 1b49f91a9b252447ab791ccef7b26a0b8b6062dd (patch) | |
tree | 1cee3846da13d317be015a6ec4c244864e8b9247 /ext/fg | |
parent | bea50cca462be631dadbd2f5bde1bc0a12ad17bf (diff) | |
parent | d263a93d446096abfc33e47f591dbb71eb7fe928 (diff) |
Merge branch 'master' into firefox-amo
Diffstat (limited to 'ext/fg')
-rw-r--r-- | ext/fg/js/driver.js | 8 | ||||
-rw-r--r-- | ext/fg/js/util.js | 16 |
2 files changed, 10 insertions, 14 deletions
diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index 49147c8f..e94a4ac2 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -172,13 +172,13 @@ window.driver = new class { } else { textSource.setEndOffset(length); - const cloze = docClozeExtract(textSource, this.options.anki.sentenceExt); + const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); const url = window.location.href; this.popup.showTermDefs( textSource.getRect(), definitions, this.options, - {cloze, url} + {sentence, url} ); this.lastTextSource = textSource; @@ -198,13 +198,13 @@ window.driver = new class { if (definitions.length === 0) { return false; } else { - const cloze = docClozeExtract(textSource, this.options.anki.sentenceExt); + const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); const url = window.location.href; this.popup.showKanjiDefs( textSource.getRect(), definitions, this.options, - {cloze, url} + {sentence, url} ); this.lastTextSource = textSource; diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js index a1bce660..e5705ffd 100644 --- a/ext/fg/js/util.js +++ b/ext/fg/js/util.js @@ -152,7 +152,7 @@ function docRangeFromPoint(point, imposter) { return null; } -function docClozeExtract(source, extent) { +function docSentenceExtract(source, extent) { const quotesFwd = {'「': '」', '『': '』', "'": "'", '"': '"'}; const quotesBwd = {'」': '「', '』': '『', "'": "'", '"': '"'}; const terminators = '…。..??!!'; @@ -182,7 +182,7 @@ function docClozeExtract(source, extent) { quoteStack = []; - let endPos = content.length - 1; + let endPos = content.length; for (let i = position; i <= endPos; ++i) { const c = content[i]; @@ -204,15 +204,11 @@ function docClozeExtract(source, extent) { } } - const sentence = content.substring(startPos, endPos); - const clozePrefix = sentence.substring(0, position - startPos); - const clozeBody = source.text(); - const clozeSuffix = sentence.substring(position - startPos + clozeBody.length); + const text = content.substring(startPos, endPos); + const padding = text.length - text.replace(/^\s+/, '').length; return { - sentence: sentence.trim(), - prefix: clozePrefix.trim(), - body: clozeBody.trim(), - suffix: clozeSuffix.trim() + text: text.trim(), + offset: position - startPos - padding }; } |