Skip to content

Commit

Permalink
ignoring keydown events for keys that don't have handlers subscribed
Browse files Browse the repository at this point in the history
  • Loading branch information
rlinoz committed Oct 30, 2023
1 parent 72b388a commit df585fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'underscore';
import getKeyEventModifiers from '@libs/KeyboardShortcut/getKeyEventModifiers';
import BindHandlerToKeydownEvent from './types';

Expand All @@ -8,6 +9,11 @@ const bindHandlerToKeydownEvent: BindHandlerToKeydownEvent = (getDisplayName, ev
const eventModifiers = getKeyEventModifiers(keyCommandEvent);
const displayName = getDisplayName(keyCommandEvent.input, eventModifiers);

// If we didn't register any event handlers for a key we ignore it
if (!eventHandlers[displayName]) {
return;
}

// Loop over all the callbacks
Object.values(eventHandlers[displayName]).every((callback) => {
// Determine if the event should bubble before executing the callback (which may have side-effects)
Expand Down
5 changes: 5 additions & 0 deletions src/libs/KeyboardShortcut/bindHandlerToKeydownEvent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ const bindHandlerToKeydownEvent: BindHandlerToKeydownEvent = (getDisplayName, ev
const eventModifiers = getKeyEventModifiers(keyCommandEvent);
const displayName = getDisplayName(keyCommandEvent.input, eventModifiers);

// If we didn't register any event handlers for a key we ignore it
if (!eventHandlers[displayName]) {
return;
}

// Loop over all the callbacks
Object.values(eventHandlers[displayName]).every((callback) => {
const textArea = event.target as HTMLTextAreaElement;
Expand Down

0 comments on commit df585fa

Please sign in to comment.