summaryrefslogtreecommitdiff
path: root/ext/js/display/display.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-02-02 21:33:47 -0500
committerGitHub <noreply@github.com>2024-02-03 02:33:47 +0000
commit6dc7e90f8d5679b0de298c820a5b88b93590ed31 (patch)
tree42616fb712c7a5a019cde592bd2980e5eb9a3539 /ext/js/display/display.js
parent711520e9a04096dba3adb1f09c0865eda5fb587c (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/display/display.js')
-rw-r--r--ext/js/display/display.js29
1 files changed, 19 insertions, 10 deletions
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;
@@ -1933,10 +1928,24 @@ export class Display extends EventDispatcher {
}
/**
+ * @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
+ }
+ };
}
/**