Skip to content

Commit b55b6f5

Browse files
authored
fix: prevent Ctrl+V in dialogs from pasting into editor (Acode-Foundation#2018)
1 parent 0459064 commit b55b6f5

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/handlers/keyboard.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default function keyboardHandler(e) {
5656
const $target = e.target;
5757
const { key, ctrlKey, shiftKey, altKey, metaKey } = e;
5858

59-
if ($target instanceof HTMLTextAreaElement) {
59+
if (shouldIgnoreEditorShortcutTarget($target)) {
6060
keydownState.esc = key === "Escape";
6161
return;
6262
}
@@ -81,6 +81,24 @@ export default function keyboardHandler(e) {
8181
target?.dispatchEvent?.(event);
8282
}
8383

84+
/**
85+
* Returns true when a keyboard event target should keep the shortcut local
86+
* instead of forwarding it into the editor.
87+
* @param {EventTarget | null} target
88+
* @returns {boolean}
89+
*/
90+
function shouldIgnoreEditorShortcutTarget(target) {
91+
if (!(target instanceof Element)) return false;
92+
93+
return (
94+
target instanceof HTMLInputElement ||
95+
target instanceof HTMLTextAreaElement ||
96+
target instanceof HTMLSelectElement ||
97+
target.isContentEditable ||
98+
!!target.closest(".prompt, #palette")
99+
);
100+
}
101+
84102
document.addEventListener("admob.banner.size", async (event) => {
85103
const { height } = event.size;
86104
MIN_KEYBOARD_HEIGHT = height + 10;

0 commit comments

Comments
 (0)