Skip to content

Commit

Permalink
Paste on search page will trigger search (#1348)
Browse files Browse the repository at this point in the history
* Paste on search page will search

* update search height when paste and not search if same input
  • Loading branch information
khaitruong922 authored Aug 25, 2024
1 parent 891a73f commit f7a6eb8
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ext/js/display/search-display-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f7a6eb8

Please sign in to comment.