Skip to content

Commit

Permalink
feat: add keybind for toggleComment
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkhav committed Jan 23, 2024
1 parent 653d497 commit 0dda1a1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/insomnia/src/common/hotkeys.ts
Expand Up @@ -37,6 +37,7 @@ export const keyboardShortcutDescriptions: Record<KeyboardShortcut, string> = {
'environment_showVariableSourceAndValue': 'Show variable source and value',
'beautifyRequestBody': 'Beautify Active Code Editors',
'graphql_explorer_focus_filter': 'Focus GraphQL Explorer Filter',
'toggle_comment': 'Toggle Line Comment',
};

/**
Expand Down Expand Up @@ -173,6 +174,10 @@ const defaultRegistry: HotKeyRegistry = {
macKeys: [{ shift: true, meta: true, keyCode: keyboardKeys.i.keyCode }],
winLinuxKeys: [{ ctrl: true, shift: true, keyCode: keyboardKeys.i.keyCode }],
},
toggle_comment: {
macKeys: [{ meta: true, keyCode: keyboardKeys.forwardslash.keyCode }],
winLinuxKeys: [{ ctrl: true, keyCode: keyboardKeys.forwardslash.keyCode }],
},
};

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/insomnia/src/common/settings.ts
Expand Up @@ -57,7 +57,8 @@ export type KeyboardShortcut =
| 'request_togglePin'
| 'environment_showVariableSourceAndValue'
| 'beautifyRequestBody'
| 'graphql_explorer_focus_filter';
| 'graphql_explorer_focus_filter'
| 'toggle_comment';

/**
* The collection of defined hotkeys.
Expand Down
Expand Up @@ -349,6 +349,9 @@ export const CodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(({
const isAutoCompleteBinding = isKeyCombinationInRegistry(pressedKeyComb, {
'showAutocomplete': settings.hotKeyRegistry.showAutocomplete,
});
const isToggleCommentBinding = isKeyCombinationInRegistry(pressedKeyComb, {
'toggle_comment': settings.hotKeyRegistry.toggle_comment,
});
// Stop the editor from handling global keyboard shortcuts except for the autocomplete binding
const isShortcutButNotAutocomplete = isUserDefinedKeyboardShortcut && !isAutoCompleteBinding;
// Should not capture escape in order to exit modals
Expand Down Expand Up @@ -376,6 +379,9 @@ export const CodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(({
}
}
}
if (isToggleCommentBinding) {
doc.execCommand('toggleComment');
}
});
// NOTE: maybe we don't need this anymore?
const persistState = () => {
Expand Down

0 comments on commit 0dda1a1

Please sign in to comment.