Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle keyboard shortcuts with Ctrl key #1690

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 11 additions & 2 deletions lib/ui/src/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,21 @@ export const Chat: React.FunctionComponent<ChatProps> = ({
event.stopPropagation()
setMessageBeingEdited(false)
onChatSubmit()
return
}

// Handles keyboard shortcuts with Ctrl key.
// 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)) {
event.preventDefault()
}

// Ignore alt + c key combination for editor to avoid conflict with cody shortcut
if (event.altKey && event.key === 'c') {
const vscodeCodyShortcuts = new Set(['Slash', 'KeyC'])
if (event.altKey && vscodeCodyShortcuts.has(event.code)) {
event.preventDefault()
event.stopPropagation()
}

// Handles cycling through chat command suggestions using the up and down arrow keys
Expand Down
1 change: 1 addition & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Starting from `0.2.0`, Cody is using `major.EVEN_NUMBER.patch` for release versi

- Fixup: Updated the fixup create task to just use the previous command text. [pull/1615](https://github.com/sourcegraph/cody/pull/1615)
- Chat: Opening files from the new chat panel will now show up beside the chat panel instead of on top of the chat panel. [pull/1677](https://github.com/sourcegraph/cody/pull/1677)
- Chat: Prevented default events on certain key combos when chat box is focused. [pull/1690](https://github.com/sourcegraph/cody/pull/1690)

### Changed

Expand Down