Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/handlers/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function keyboardHandler(e) {
const $target = e.target;
const { key, ctrlKey, shiftKey, altKey, metaKey } = e;

if ($target instanceof HTMLTextAreaElement) {
if (shouldIgnoreEditorShortcutTarget($target)) {
keydownState.esc = key === "Escape";
return;
}
Expand All @@ -81,6 +81,24 @@ export default function keyboardHandler(e) {
target?.dispatchEvent?.(event);
}

/**
* Returns true when a keyboard event target should keep the shortcut local
* instead of forwarding it into the editor.
* @param {EventTarget | null} target
* @returns {boolean}
*/
function shouldIgnoreEditorShortcutTarget(target) {
if (!(target instanceof Element)) return false;

return (
target instanceof HTMLInputElement ||
target instanceof HTMLTextAreaElement ||
target instanceof HTMLSelectElement ||
target.isContentEditable ||
!!target.closest(".prompt, #palette")
);
}

document.addEventListener("admob.banner.size", async (event) => {
const { height } = event.size;
MIN_KEYBOARD_HEIGHT = height + 10;
Expand Down