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/display/display.js | 29 +++++++++++++++++++---------- ext/js/display/query-parser.js | 35 +++++++++++++---------------------- 2 files changed, 32 insertions(+), 32 deletions(-) (limited to 'ext/js/display') diff --git a/ext/js/display/display.js b/ext/js/display/display.js index 4114cc45..676f1a4f 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -1850,7 +1850,8 @@ export class Display extends EventDispatcher { 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)); + this._contentTextScanner.on('searchSuccess', this._onContentTextScannerSearchSuccess.bind(this)); + this._contentTextScanner.on('searchError', this._onContentTextScannerSearchError.bind(this)); } const {scanning: scanningOptions, sentenceParsing: sentenceParsingOptions} = options; @@ -1895,15 +1896,9 @@ export class Display extends EventDispatcher { } /** - * @param {import('text-scanner').SearchedEventDetails} details + * @param {import('text-scanner').EventArgument<'searchSuccess'>} details */ - _onContentTextScannerSearched({type, dictionaryEntries, sentence, textSource, optionsContext, error}) { - if (error !== null && !this._application.webExtension.unloaded) { - log.error(error); - } - - if (type === null) { return; } - + _onContentTextScannerSearchSuccess({type, dictionaryEntries, sentence, textSource, optionsContext}) { const query = textSource.text(); const url = window.location.href; const documentTitle = document.title; @@ -1932,11 +1927,25 @@ export class Display extends EventDispatcher { this.setContent(details); } + /** + * @param {import('text-scanner').EventArgument<'searchError'>} details + */ + _onContentTextScannerSearchError({error}) { + if (!this._application.webExtension.unloaded) { + log.error(error); + } + } + /** * @type {import('display').GetSearchContextCallback} */ _getSearchContext() { - return {optionsContext: this.getOptionsContext()}; + return { + optionsContext: this.getOptionsContext(), + detail: { + documentTitle: document.title + } + }; } /** diff --git a/ext/js/display/query-parser.js b/ext/js/display/query-parser.js index daa298d2..6ec803a0 100644 --- a/ext/js/display/query-parser.js +++ b/ext/js/display/query-parser.js @@ -82,7 +82,8 @@ export 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._textScanner.on('searchSuccess', this._onSearchSuccess.bind(this)); + this._textScanner.on('searchError', this._onSearchError.bind(this)); this._queryParserModeSelect.addEventListener('change', this._onParserChange.bind(this), false); } @@ -147,38 +148,28 @@ export class QueryParser extends EventDispatcher { } /** - * @param {import('text-scanner').SearchedEventDetails} e + * @param {import('text-scanner').EventArgument<'searchSuccess'>} details */ - _onSearched(e) { - const {error} = e; - if (error !== null) { - log.error(error); - return; - } - - const { - textScanner, - type, - dictionaryEntries, - sentence, - inputInfo, - textSource, - optionsContext - } = e; - if (type === null || dictionaryEntries === null || sentence === null || optionsContext === null) { return; } - + _onSearchSuccess({type, dictionaryEntries, sentence, inputInfo, textSource, optionsContext}) { this.trigger('searched', { - textScanner, + textScanner: this._textScanner, type, dictionaryEntries, sentence, inputInfo, textSource, optionsContext, - sentenceOffset: this._getSentenceOffset(e.textSource) + sentenceOffset: this._getSentenceOffset(textSource) }); } + /** + * @param {import('text-scanner').EventArgument<'searchError'>} details + */ + _onSearchError({error}) { + log.error(error); + } + /** * @param {Event} e */ -- cgit v1.2.3