diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-05-19 20:09:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-19 20:09:37 -0400 |
commit | 6184bcb812686f5498ee982ae89da88792b9a880 (patch) | |
tree | b64fd9b45fe8909c3c5e553af701e6ae18fc0170 /ext/js/display | |
parent | eddd0288643f08d2a2c85f73575bc7ee1c157539 (diff) |
Selection clear improvements (#1690)
* Update selection clear process
* Clean up old clearSelection API
* Update clear order
* Add clear event handling
Diffstat (limited to 'ext/js/display')
-rw-r--r-- | ext/js/display/display.js | 8 | ||||
-rw-r--r-- | ext/js/display/query-parser.js | 5 |
2 files changed, 12 insertions, 1 deletions
diff --git a/ext/js/display/display.js b/ext/js/display/display.js index fe5b5c9a..bb089047 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -1771,6 +1771,7 @@ class Display extends EventDispatcher { if (!options.scanning.enablePopupSearch) { if (this._contentTextScanner !== null) { this._contentTextScanner.setEnabled(false); + this._contentTextScanner.clearSelection(); } return; } @@ -1788,6 +1789,7 @@ class Display extends EventDispatcher { this._contentTextScanner.includeSelector = '.click-scannable,.click-scannable *'; this._contentTextScanner.excludeSelector = '.scan-disable,.scan-disable *'; this._contentTextScanner.prepare(); + this._contentTextScanner.on('clear', this._onContentTextScannerClear.bind(this)); this._contentTextScanner.on('searched', this._onContentTextScannerSearched.bind(this)); } @@ -1821,6 +1823,10 @@ class Display extends EventDispatcher { this._contentTextScanner.setEnabled(true); } + _onContentTextScannerClear() { + this._contentTextScanner.clearSelection(); + } + _onContentTextScannerSearched({type, dictionaryEntries, sentence, textSource, optionsContext, error}) { if (error !== null && !yomichan.isExtensionUnloaded) { log.error(error); @@ -1851,7 +1857,7 @@ class Display extends EventDispatcher { contentOrigin: this.getContentOrigin() } }; - this._contentTextScanner.clearSelection(true); + this._contentTextScanner.clearSelection(); this.setContent(details); } diff --git a/ext/js/display/query-parser.js b/ext/js/display/query-parser.js index 8c5ce331..39b09646 100644 --- a/ext/js/display/query-parser.js +++ b/ext/js/display/query-parser.js @@ -47,6 +47,7 @@ class QueryParser extends EventDispatcher { prepare() { this._textScanner.prepare(); + this._textScanner.on('clear', this._onTextScannerClear.bind(this)); this._textScanner.on('searched', this._onSearched.bind(this)); this._queryParserModeSelect.addEventListener('change', this._onParserChange.bind(this), false); } @@ -86,6 +87,10 @@ class QueryParser extends EventDispatcher { // Private + _onTextScannerClear() { + this._textScanner.clearSelection(); + } + _onSearched(e) { const {error} = e; if (error !== null) { |