From 0dda1a1a1ee6b6d0dfa4194fa789de2f5c0aa8af Mon Sep 17 00:00:00 2001 From: Amon Khavari Date: Thu, 30 Nov 2023 22:57:11 +0100 Subject: [PATCH] feat: add keybind for toggleComment --- packages/insomnia/src/common/hotkeys.ts | 5 +++++ packages/insomnia/src/common/settings.ts | 3 ++- .../insomnia/src/ui/components/codemirror/code-editor.tsx | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/insomnia/src/common/hotkeys.ts b/packages/insomnia/src/common/hotkeys.ts index 0f4d7fb3ede..0da5da32a9c 100644 --- a/packages/insomnia/src/common/hotkeys.ts +++ b/packages/insomnia/src/common/hotkeys.ts @@ -37,6 +37,7 @@ export const keyboardShortcutDescriptions: Record = { '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', }; /** @@ -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 }], + }, }; /** diff --git a/packages/insomnia/src/common/settings.ts b/packages/insomnia/src/common/settings.ts index 460412427c1..b810c09492c 100644 --- a/packages/insomnia/src/common/settings.ts +++ b/packages/insomnia/src/common/settings.ts @@ -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. diff --git a/packages/insomnia/src/ui/components/codemirror/code-editor.tsx b/packages/insomnia/src/ui/components/codemirror/code-editor.tsx index 91062c7db11..029676a4817 100644 --- a/packages/insomnia/src/ui/components/codemirror/code-editor.tsx +++ b/packages/insomnia/src/ui/components/codemirror/code-editor.tsx @@ -349,6 +349,9 @@ export const CodeEditor = forwardRef(({ 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 @@ -376,6 +379,9 @@ export const CodeEditor = forwardRef(({ } } } + if (isToggleCommentBinding) { + doc.execCommand('toggleComment'); + } }); // NOTE: maybe we don't need this anymore? const persistState = () => {