diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2024-02-02 21:33:47 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-03 02:33:47 +0000 |
commit | 6dc7e90f8d5679b0de298c820a5b88b93590ed31 (patch) | |
tree | 42616fb712c7a5a019cde592bd2980e5eb9a3539 /ext/js/app | |
parent | 711520e9a04096dba3adb1f09c0865eda5fb587c (diff) |
Fix auto hide search popup (#592)
* Remove return
* Update searched event
* Fix auto-hide search popup event not occuring
* Add TODO
* Split into multiple events
Diffstat (limited to 'ext/js/app')
-rw-r--r-- | ext/js/app/frontend.js | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/ext/js/app/frontend.js b/ext/js/app/frontend.js index de1c5a46..5f412340 100644 --- a/ext/js/app/frontend.js +++ b/ext/js/app/frontend.js @@ -183,7 +183,9 @@ export class Frontend { chrome.runtime.onMessage.addListener(this._onRuntimeMessage.bind(this)); this._textScanner.on('clear', this._onTextScannerClear.bind(this)); - this._textScanner.on('searched', this._onSearched.bind(this)); + this._textScanner.on('searchSuccess', this._onSearchSuccess.bind(this)); + this._textScanner.on('searchEmpty', this._onSearchEmpty.bind(this)); + this._textScanner.on('searchError', this._onSearchError.bind(this)); /* eslint-disable no-multi-spaces */ this._application.crossFrame.registerHandlers([ @@ -369,31 +371,36 @@ export class Frontend { } /** - * @param {import('text-scanner').SearchedEventDetails} details + * @param {import('text-scanner').EventArgument<'searchSuccess'>} details */ - _onSearched({type, dictionaryEntries, sentence, inputInfo: {eventType, passive, detail: inputInfoDetail}, textSource, optionsContext, detail, error}) { + _onSearchSuccess({type, dictionaryEntries, sentence, inputInfo: {eventType, detail: inputInfoDetail}, textSource, optionsContext, detail}) { + this._stopClearSelectionDelayed(); + let focus = (eventType === 'mouseMove'); + if (typeof inputInfoDetail === 'object' && inputInfoDetail !== null) { + const focus2 = inputInfoDetail.focus; + if (typeof focus2 === 'boolean') { focus = focus2; } + } + this._showContent(textSource, focus, dictionaryEntries, type, sentence, detail !== null ? detail.documentTitle : null, optionsContext); + } + + /** */ + _onSearchEmpty() { const scanningOptions = /** @type {import('settings').ProfileOptions} */ (this._options).scanning; + if (scanningOptions.autoHideResults) { + this._clearSelectionDelayed(scanningOptions.hideDelay, false, false); + } + } - if (error !== null) { - if (this._application.webExtension.unloaded) { - if (textSource !== null && !passive) { - this._showExtensionUnloaded(textSource); - } - } else { - log.error(error); - } - } if (type !== null && optionsContext !== null) { - this._stopClearSelectionDelayed(); - let focus = (eventType === 'mouseMove'); - if (typeof inputInfoDetail === 'object' && inputInfoDetail !== null) { - const focus2 = inputInfoDetail.focus; - if (typeof focus2 === 'boolean') { focus = focus2; } + /** + * @param {import('text-scanner').EventArgument<'searchError'>} details + */ + _onSearchError({error, textSource, inputInfo: {passive}}) { + if (this._application.webExtension.unloaded) { + if (textSource !== null && !passive) { + this._showExtensionUnloaded(textSource); } - this._showContent(textSource, focus, dictionaryEntries, type, sentence, detail !== null ? detail.documentTitle : null, optionsContext); } else { - if (scanningOptions.autoHideResults) { - this._clearSelectionDelayed(scanningOptions.hideDelay, false, false); - } + log.error(error); } } @@ -888,7 +895,7 @@ export class Frontend { } /** - * @returns {Promise<{optionsContext: import('settings').OptionsContext, detail?: import('text-scanner').SearchResultDetail}>} + * @returns {Promise<import('text-scanner').SearchContext>} */ async _getSearchContext() { let url = window.location.href; |