aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/display.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-08-01 16:33:21 -0400
committerGitHub <noreply@github.com>2020-08-01 16:33:21 -0400
commita562a1149808b49f60346c82409f292290fbdd77 (patch)
tree033e9195a9eb47e8b34679b393b0d5f5c753ce90 /ext/mixed/js/display.js
parentf271c83d77c1e304925c094ec0e13761b28d6705 (diff)
Display try catch refactor (#704)
* Remove try-catch from _termLookup Already handled by _onTermLookup * Move try-catch out of _onTermLookup and into _onGlossaryMouseUp
Diffstat (limited to 'ext/mixed/js/display.js')
-rw-r--r--ext/mixed/js/display.js104
1 files changed, 50 insertions, 54 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 40febadc..ab0f59a5 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -521,78 +521,74 @@ class Display extends EventDispatcher {
_onGlossaryMouseUp(e) {
if (!this._clickScanPrevent && DOM.isMouseButtonPressed(e, 'primary')) {
- this._onTermLookup(e);
+ try {
+ this._onTermLookup(e);
+ } catch (error) {
+ this.onError(error);
+ }
}
}
async _onTermLookup(e) {
- try {
- if (!this._historyHasState()) { return; }
+ if (!this._historyHasState()) { return; }
- const termLookupResults = await this._termLookup(e);
- if (!termLookupResults || !this._historyHasState()) { return; }
+ const termLookupResults = await this._termLookup(e);
+ if (!termLookupResults || !this._historyHasState()) { return; }
- const {state} = this._history;
- const {textSource, definitions} = termLookupResults;
+ const {state} = this._history;
+ const {textSource, definitions} = termLookupResults;
- const scannedElement = e.target;
- const sentenceExtent = this._options.anki.sentenceExt;
- const layoutAwareScan = this._options.scanning.layoutAwareScan;
- const sentence = docSentenceExtract(textSource, sentenceExtent, layoutAwareScan);
+ const scannedElement = e.target;
+ const sentenceExtent = this._options.anki.sentenceExt;
+ const layoutAwareScan = this._options.scanning.layoutAwareScan;
+ const sentence = docSentenceExtract(textSource, sentenceExtent, layoutAwareScan);
- state.focusEntry = this._entryIndexFind(scannedElement);
- state.scrollX = this._windowScroll.x;
- state.scrollY = this._windowScroll.y;
- this._historyStateUpdate(state);
+ state.focusEntry = this._entryIndexFind(scannedElement);
+ state.scrollX = this._windowScroll.x;
+ state.scrollY = this._windowScroll.y;
+ this._historyStateUpdate(state);
- const query = textSource.text();
- const details = {
- focus: false,
- history: true,
- params: this._createSearchParams('terms', query, false),
- state: {
- focusEntry: 0,
- sentence,
- url: state.url
- },
- content: {
- definitions
- }
- };
- this.setContent(details);
- } catch (error) {
- this.onError(error);
- }
+ const query = textSource.text();
+ const details = {
+ focus: false,
+ history: true,
+ params: this._createSearchParams('terms', query, false),
+ state: {
+ focusEntry: 0,
+ sentence,
+ url: state.url
+ },
+ content: {
+ definitions
+ }
+ };
+ this.setContent(details);
}
async _termLookup(e) {
- try {
- e.preventDefault();
-
- const {length: scanLength, deepDomScan: deepScan, layoutAwareScan} = this._options.scanning;
- const textSource = docRangeFromPoint(e.clientX, e.clientY, deepScan);
- if (textSource === null) {
- return false;
- }
+ e.preventDefault();
- let definitions, length;
- try {
- textSource.setEndOffset(scanLength, layoutAwareScan);
+ const {length: scanLength, deepDomScan: deepScan, layoutAwareScan} = this._options.scanning;
+ const textSource = docRangeFromPoint(e.clientX, e.clientY, deepScan);
+ if (textSource === null) {
+ return false;
+ }
- ({definitions, length} = await api.termsFind(textSource.text(), {}, this.getOptionsContext()));
- if (definitions.length === 0) {
- return false;
- }
+ let definitions, length;
+ try {
+ textSource.setEndOffset(scanLength, layoutAwareScan);
- textSource.setEndOffset(length, layoutAwareScan);
- } finally {
- textSource.cleanup();
+ ({definitions, length} = await api.termsFind(textSource.text(), {}, this.getOptionsContext()));
+ if (definitions.length === 0) {
+ return false;
}
- return {textSource, definitions};
- } catch (error) {
- this.onError(error);
+ textSource.setEndOffset(length, layoutAwareScan);
+ } finally {
+ textSource.cleanup();
}
+
+ return {textSource, definitions};
}
_onAudioPlay(e) {