handle paste
This commit is contained in:
+14
-2
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user