Skip to content

Commit

Permalink
Ignore keyboard shortcuts when target is contenteditable (#1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovidiuch committed Mar 1, 2024
1 parent 2b25174 commit 5364b02
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function registerPlaygroundShortcuts(

function handleWindowKeyDown(e: KeyboardEvent) {
// Allow meta key shortcuts to work when focused on input fields
if (isEditing() && !e.metaKey) {
if (isEditing(e) && !e.metaKey) {
return;
}

Expand Down Expand Up @@ -45,7 +45,11 @@ export function registerPlaygroundShortcuts(
};
}

function isEditing() {
function isEditing(e: KeyboardEvent) {
if (e.target instanceof HTMLElement && e.target.isContentEditable) {
return true;
}

const activeElement = document.activeElement;
return activeElement && isInputTag(activeElement.tagName);
}
Expand Down

0 comments on commit 5364b02

Please sign in to comment.