From 6c082956a37f2849eb7f517e49bfef1136ba2e8f Mon Sep 17 00:00:00 2001 From: cade Date: Sat, 21 Mar 2026 00:45:58 +0000 Subject: [PATCH] handle paste --- index.html | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 22a4c9a..e4336bb 100644 --- a/index.html +++ b/index.html @@ -352,6 +352,7 @@ this.#input.addEventListener('input', this.#onInput); this.#suggestions.addEventListener('click', this.#onSuggestionClick); document.addEventListener('keydown', this.#onKeydown); + document.addEventListener('paste', this.#onPaste); this.shadowRoot.append(clone); } @@ -491,7 +492,7 @@ } suggestions = suggestions.filter( - (s) => s.startsWith(oq.query) || s.includes(oq.query), + (s) => s.startsWith(oq.query) || s.includes(oq.query) ); } @@ -504,7 +505,7 @@ suggestions = [...suggestions, ...ddgSuggestions].slice( 0, - CONFIG.suggestionLimit, + CONFIG.suggestionLimit ); } @@ -513,6 +514,17 @@ this.#renderSuggestions(suggestions, oq.query); }; + #onPaste = (e) => { + if (this.#dialog.open) return; + const text = e.clipboardData?.getData('text'); + if (!text) return; + e.preventDefault(); + this.#dialog.show(); + this.#input.focus(); + this.#input.value = text; + this.#onInput(); + }; + #onKeydown = (e) => { if (!this.#dialog.open) { this.#dialog.show();