From f7a6eb811ce9cb0fb8fa07d58f753873a7f8e0ea Mon Sep 17 00:00:00 2001 From: Khai Truong <56820749+khaitruong922@users.noreply.github.com> Date: Sun, 25 Aug 2024 22:54:38 +0700 Subject: [PATCH] Paste on search page will trigger search (#1348) * Paste on search page will search * update search height when paste and not search if same input --- ext/js/display/search-display-controller.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ext/js/display/search-display-controller.js b/ext/js/display/search-display-controller.js index 522b11a2c..c664fc849 100644 --- a/ext/js/display/search-display-controller.js +++ b/ext/js/display/search-display-controller.js @@ -107,6 +107,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)); + window.addEventListener('paste', this._onPaste.bind(this)); this._clipboardMonitor.on('change', this._onClipboardMonitorChange.bind(this)); this._clipboardMonitorEnableCheckbox.addEventListener('change', this._onClipboardMonitorEnableChange.bind(this)); this._stickyHeaderEnableCheckbox.addEventListener('change', this._onStickyHeaderEnableChange.bind(this)); @@ -278,6 +279,26 @@ export class SearchDisplayController { this._clipboardMonitor.setPreviousText(document.hasFocus() ? await this._clipboardReaderLike.getText(false) : ''); } + /** + * @param {ClipboardEvent} e + */ + _onPaste(e) { + if (e.target === this._queryInput) { + return; + } + e.stopPropagation(); + e.preventDefault(); + const text = e.clipboardData?.getData('text'); + if (!text) { + return; + } + if (this._queryInput.value !== text) { + this._queryInput.value = text; + this._updateSearchHeight(true); + this._searchButton.click(); + } + } + /** @type {import('application').ApiHandler<'searchDisplayControllerUpdateSearchQuery'>} */ _onExternalSearchUpdate({text, animate}) { void this._updateSearchFromClipboard(text, animate, false);