summaryrefslogtreecommitdiff
path: root/ext/fg/js/util.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-03-27 22:48:50 -0700
committerAlex Yatskov <alex@foosoft.net>2017-03-27 22:48:50 -0700
commit9de0d34af398b385e140a365a500ff20dda45a7a (patch)
treeb6776b5b55dc764676c6312822b38e9c484bd8d9 /ext/fg/js/util.js
parent3b0aa88de11427c841f85e860aef91ff5d5c793d (diff)
wip
Diffstat (limited to 'ext/fg/js/util.js')
-rw-r--r--ext/fg/js/util.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js
index be809bfb..0a95b24d 100644
--- a/ext/fg/js/util.js
+++ b/ext/fg/js/util.js
@@ -152,7 +152,7 @@ function docRangeFromPoint(point, imposter) {
return null;
}
-function docSentenceExtract(source, extent) {
+function docClozeExtract(source, extent) {
const quotesFwd = {'「': '」', '『': '』', "'": "'", '"': '"'};
const quotesBwd = {'」': '「', '』': '『', "'": "'", '"': '"'};
const terminators = '…。..??!!';
@@ -182,8 +182,8 @@ function docSentenceExtract(source, extent) {
quoteStack = [];
- let endPos = content.length;
- for (let i = position; i < endPos; ++i) {
+ let endPos = content.length - 1;
+ for (let i = position; i <= endPos; ++i) {
const c = content[i];
if (quoteStack.length === 0) {
@@ -204,5 +204,15 @@ function docSentenceExtract(source, extent) {
}
}
- return content.substring(startPos, endPos).trim();
+ 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);
+
+ return {
+ sentence: sentence.trim(),
+ prefix: clozePrefix.trim(),
+ body: clozeBody.trim(),
+ sufix: clozeSuffix.trim()
+ };
}