Skip to content

Commit

Permalink
fix: only prevent default on Ctrl key combo (#2558)
Browse files Browse the repository at this point in the history
Close #2383

The previous check for Ctrl or AltGraph being pressed was too broad and
prevented some default browser shortcuts from working properly, and
created blockers for users on different keyboard layouts

This fixes it by checking specifically for Ctrl keys combo only.

Alt + C is still prevented. 

## Test plan

<!-- Required. See
https://sourcegraph.com/docs/dev/background-information/testing_principles.
-->

1. Try using alt + key combos when focusing in input box - this should
now work
2. Try pressing alt + c when focusing in input box - this should open
the command menu
  • Loading branch information
abeatrix authored Jan 4, 2024
1 parent e45f5ed commit 60899dd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ui/src/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export const Chat: React.FunctionComponent<ChatProps> = ({
// Checks if the Ctrl key is pressed with a key not in the allow list
// to avoid triggering default browser shortcuts and bubbling the event.
const ctrlKeysAllowList = new Set(['a', 'c', 'v', 'x', 'y', 'z'])
if ((event.ctrlKey || event.getModifierState('AltGraph')) && !ctrlKeysAllowList.has(event.key)) {
if (event.ctrlKey && !ctrlKeysAllowList.has(event.key)) {
event.preventDefault()
return
}
Expand Down

0 comments on commit 60899dd

Please sign in to comment.