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

feat: add customizable shortcut for toggling comment in editor #6889

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions packages/insomnia/src/common/hotkeys.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,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 @@ -377,6 +380,9 @@ export const CodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(({
}
}
}
if (isToggleCommentBinding) {
doc.execCommand('toggleComment');
}
});
// NOTE: maybe we don't need this anymore?
const persistState = () => {
Expand Down