This commit is contained in:
Alex Yatskov 2017-04-07 21:17:13 -07:00
parent bbe4afecf6
commit c4b1a4a5b4
4 changed files with 16 additions and 16 deletions

View File

@ -172,13 +172,13 @@ window.driver = new class {
} else { } else {
textSource.setEndOffset(length); textSource.setEndOffset(length);
const cloze = docClozeExtract(textSource, this.options.anki.sentenceExt); const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt);
const url = window.location.href; const url = window.location.href;
this.popup.showTermDefs( this.popup.showTermDefs(
textSource.getRect(), textSource.getRect(),
definitions, definitions,
this.options, this.options,
{cloze, url} {sentence, url}
); );
this.lastTextSource = textSource; this.lastTextSource = textSource;
@ -198,13 +198,13 @@ window.driver = new class {
if (definitions.length === 0) { if (definitions.length === 0) {
return false; return false;
} else { } else {
const cloze = docClozeExtract(textSource, this.options.anki.sentenceExt); const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt);
const url = window.location.href; const url = window.location.href;
this.popup.showKanjiDefs( this.popup.showKanjiDefs(
textSource.getRect(), textSource.getRect(),
definitions, definitions,
this.options, this.options,
{cloze, url} {sentence, url}
); );
this.lastTextSource = textSource; this.lastTextSource = textSource;

View File

@ -152,7 +152,7 @@ function docRangeFromPoint(point, imposter) {
return null; return null;
} }
function docClozeExtract(source, extent) { function docSentenceExtract(source, extent) {
const quotesFwd = {'「': '」', '『': '』', "'": "'", '"': '"'}; const quotesFwd = {'「': '」', '『': '』', "'": "'", '"': '"'};
const quotesBwd = {'」': '「', '』': '『', "'": "'", '"': '"'}; const quotesBwd = {'」': '「', '』': '『', "'": "'", '"': '"'};
const terminators = '…。..?!'; const terminators = '…。..?!';
@ -204,11 +204,11 @@ function docClozeExtract(source, extent) {
} }
} }
const sentence = content.substring(startPos, endPos); const text = content.substring(startPos, endPos);
const padding = sentence.length - sentence.replace(/^\s+/, ''); const padding = text.length - text.replace(/^\s+/, '');
return { return {
sentence: sentence.trim(), text: text.trim(),
offset: position - startPos - padding offset: position - startPos - padding
}; };
} }

View File

@ -74,7 +74,7 @@ class Display {
if (context) { if (context) {
for (const definition of definitions) { for (const definition of definitions) {
definition.cloze = clozeBuild(context.cloze); definition.cloze = clozeBuild(context.sentence, definition.source);
definition.url = context.url; definition.url = context.url;
} }
} }
@ -108,7 +108,7 @@ class Display {
if (context) { if (context) {
for (const definition of definitions) { for (const definition of definitions) {
definition.cloze = clozeBuild(context.cloze); definition.cloze = clozeBuild(context.sentence, definition.source);
definition.url = context.url; definition.url = context.url;
} }
} }
@ -181,7 +181,7 @@ class Display {
}; };
if (this.context) { if (this.context) {
context.cloze = this.context.cloze; context.sentence = this.context.sentence;
context.url = this.context.url; context.url = this.context.url;
} }
@ -308,7 +308,7 @@ class Display {
if (this.context && this.context.source) { if (this.context && this.context.source) {
const context = { const context = {
url: this.context.source.url, url: this.context.source.url,
cloze: this.context.source.cloze, sentence: this.context.source.sentence,
index: this.context.source.index index: this.context.source.index
}; };

View File

@ -21,12 +21,12 @@
* Cloze * Cloze
*/ */
function clozeBuild(sentence, offset, source) { function clozeBuild(sentence, source) {
return { return {
sentence: sentence.trim(), sentence: sentence.text.trim(),
prefix: sentence.substring(0, offset).trim(), prefix: sentence.text.substring(0, sentence.offset).trim(),
body: source.trim(), body: source.trim(),
suffix: sentence.substring(offset + source.length).trim() suffix: sentence.text.substring(sentence.offset + source.length).trim()
}; };
} }