From befee9ceca1a8a74b0cb70ae5b29f42f2d8f8e26 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 26 Nov 2019 10:49:55 -0500 Subject: [PATCH 1/3] Pass kanji character to clozeBuild --- ext/mixed/js/display.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index cbf8efb7..2f10da30 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -398,7 +398,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; } From afddec66eb749aa0a39c7e7142f929e68697995d Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 26 Nov 2019 10:50:29 -0500 Subject: [PATCH 2/3] Update cloze.body to use original sentence text --- ext/mixed/js/display.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 2f10da30..21d00bbc 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -640,7 +640,7 @@ class Display { if (source) { result.prefix = sentence.text.substring(0, sentence.offset).trim(); - result.body = source.trim(); + result.body = sentence.text.substring(sentence.offset, sentence.offset + source.length); result.suffix = sentence.text.substring(sentence.offset + source.length).trim(); } From 3a7ef6c560fc6437dc33ad197c136af4498db15c Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 26 Nov 2019 10:53:21 -0500 Subject: [PATCH 3/3] Simplify clozeBuild --- ext/mixed/js/display.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 21d00bbc..f231fab5 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -633,18 +633,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 = sentence.text.substring(sentence.offset, sentence.offset + source.length); - result.suffix = sentence.text.substring(sentence.offset + source.length).trim(); - } - - return result; } entryIndexFind(element) {