summaryrefslogtreecommitdiff
path: root/ext/js/display/search-display-controller.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-02-25 11:20:44 -0500
committerGitHub <noreply@github.com>2024-02-25 16:20:44 +0000
commit2e9ea19207a7410f929bb908759d48cb2340f29c (patch)
treea6bde1297d693bb8d50e4c93a963aa3179e5a2ce /ext/js/display/search-display-controller.js
parent73169f06dff767020718a5715eba97d3575ba7e1 (diff)
"isJapanese" check move (#730)
* Move isStringPartiallyJapanese out of ClipboardMonitor * Create isStringPartiallyJapanese function * Add textMayBeTranslatable * Rename API function * Rename internal function * Add helper * Update translatable check * Pass language to TextScanner * Pass language explicitly * Use textMayBeTranslatable * No redundant translatable check * Update eslint * Remove double newline * Collapse * Rename
Diffstat (limited to 'ext/js/display/search-display-controller.js')
-rw-r--r--ext/js/display/search-display-controller.js21
1 files changed, 19 insertions, 2 deletions
diff --git a/ext/js/display/search-display-controller.js b/ext/js/display/search-display-controller.js
index e23d5d50..00f5efc6 100644
--- a/ext/js/display/search-display-controller.js
+++ b/ext/js/display/search-display-controller.js
@@ -103,7 +103,7 @@ export class SearchDisplayController {
this._searchBackButton.addEventListener('click', this._onSearchBackButtonClick.bind(this), false);
this._wanakanaEnableCheckbox.addEventListener('change', this._onWanakanaEnableChange.bind(this));
window.addEventListener('copy', this._onCopy.bind(this));
- this._clipboardMonitor.on('change', this._onExternalSearchUpdate.bind(this));
+ this._clipboardMonitor.on('change', this._onClipboardMonitorChange.bind(this));
this._clipboardMonitorEnableCheckbox.addEventListener('change', this._onClipboardMonitorEnableChange.bind(this));
this._display.hotkeyHandler.on('keydownNonHotkey', this._onKeyDown.bind(this));
@@ -271,9 +271,26 @@ export class SearchDisplayController {
}
/** @type {import('application').ApiHandler<'searchDisplayControllerUpdateSearchQuery'>} */
- _onExternalSearchUpdate({text, animate = true}) {
+ _onExternalSearchUpdate({text, animate}) {
+ void this._updateSearchFromClipboard(text, animate, false);
+ }
+
+ /**
+ * @param {import('clipboard-monitor').Events['change']} event
+ */
+ _onClipboardMonitorChange({text}) {
+ void this._updateSearchFromClipboard(text, true, true);
+ }
+
+ /**
+ * @param {string} text
+ * @param {boolean} animate
+ * @param {boolean} checkText
+ */
+ async _updateSearchFromClipboard(text, animate, checkText) {
const options = this._display.getOptions();
if (options === null) { return; }
+ if (checkText && !await this._display.application.api.isTextLookupWorthy(text, options.general.language)) { return; }
const {clipboard: {autoSearchContent, maximumSearchLength}} = options;
if (text.length > maximumSearchLength) {
text = text.substring(0, maximumSearchLength);