diff options
author | Alex Yatskov <alex@foosoft.net> | 2019-09-02 11:47:14 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2019-09-02 11:47:14 -0700 |
commit | 5347da528bd07166b4686f45440d80a77f4888a3 (patch) | |
tree | 08bbfd0c859327ee9a08ca86afd222a222ced62b /ext/mixed/js/display.js | |
parent | da981c0b911dc5a697246006089b266fddba84a7 (diff) | |
parent | 4ac55da7dd5354e6c3495f04583352d0d863b7b6 (diff) |
Merge branch 'master' into testing
Diffstat (limited to 'ext/mixed/js/display.js')
-rw-r--r-- | ext/mixed/js/display.js | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index a2707bd0..ebf56897 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -80,20 +80,26 @@ class Display { const {docRangeFromPoint, docSentenceExtract} = this.dependencies; const clickedElement = $(e.target); - const textSource = docRangeFromPoint({x: e.clientX, y: e.clientY}); + const textSource = docRangeFromPoint({x: e.clientX, y: e.clientY}, this.options); if (textSource === null) { return false; } - textSource.setEndOffset(this.options.scanning.length); - const {definitions, length} = await apiTermsFind(textSource.text()); - if (definitions.length === 0) { - return false; - } + let definitions, length, sentence; + try { + textSource.setEndOffset(this.options.scanning.length); - textSource.setEndOffset(length); + ({definitions, length} = await apiTermsFind(textSource.text())); + if (definitions.length === 0) { + return false; + } - const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); + textSource.setEndOffset(length); + + sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); + } finally { + textSource.cleanup(); + } const context = { source: { |