From 6dc7e90f8d5679b0de298c820a5b88b93590ed31 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 2 Feb 2024 21:33:47 -0500 Subject: 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 --- ext/js/app/frontend.js | 51 ++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'ext/js/app') 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} */ async _getSearchContext() { let url = window.location.href; -- cgit v1.2.3