Merge pull request #291 from toasted-nutbread/cloze-fixes

Cloze fixes
This commit is contained in:
Alex Yatskov 2019-12-03 14:19:33 -08:00 committed by GitHub
commit a24146538c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -422,7 +422,7 @@ class Display {
};
for (const definition of definitions) {
definition.cloze = Display.clozeBuild(context.sentence);
definition.cloze = Display.clozeBuild(context.sentence, definition.character);
definition.url = context.url;
}
@ -686,18 +686,13 @@ class Display {
return index >= 0 && index < entries.length ? entries[index] : null;
}
static clozeBuild(sentence, source) {
const result = {
sentence: sentence.text.trim()
static clozeBuild({text, offset}, source) {
return {
sentence: text.trim(),
prefix: text.substring(0, offset).trim(),
body: text.substring(offset, offset + source.length),
suffix: text.substring(offset + source.length).trim()
};
if (source) {
result.prefix = sentence.text.substring(0, sentence.offset).trim();
result.body = source.trim();
result.suffix = sentence.text.substring(sentence.offset + source.length).trim();
}
return result;
}
entryIndexFind(element) {