From 33a7580e464d41ff269215f294b622cae21d36b0 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Mon, 18 Sep 2023 20:08:15 +0530 Subject: [PATCH] fix: support modal popping up on typing shift based commands on input --- .../src/helpers/keybindings.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/hoppscotch-common/src/helpers/keybindings.ts b/packages/hoppscotch-common/src/helpers/keybindings.ts index 9423bf9cb..499bc2ce4 100644 --- a/packages/hoppscotch-common/src/helpers/keybindings.ts +++ b/packages/hoppscotch-common/src/helpers/keybindings.ts @@ -17,6 +17,7 @@ let keybindingsEnabled = true type ModifierKeys = | "ctrl" | "alt" + | "shift" | "ctrl-shift" | "alt-shift" | "ctrl-alt" @@ -39,7 +40,6 @@ type SingleCharacterShortcutKey = `${Key}` type ShortcutKey = ModifierBasedShortcutKey | SingleCharacterShortcutKey export const bindings: { - // eslint-disable-next-line no-unused-vars [_ in ShortcutKey]?: HoppActionWithNoArgs } = { "ctrl-enter": "request.send-cancel", @@ -100,6 +100,8 @@ function handleKeyDown(ev: KeyboardEvent) { } function generateKeybindingString(ev: KeyboardEvent): ShortcutKey | null { + const target = ev.target + // We may or may not have a modifier key const modifierKey = getActiveModifier(ev) @@ -108,9 +110,18 @@ function generateKeybindingString(ev: KeyboardEvent): ShortcutKey | null { if (!key) return null // All key combos backed by modifiers are valid shortcuts (whether currently typing or not) - if (modifierKey) return `${modifierKey}-${key}` + if (modifierKey) { + // If the modifier is shift and the target is an input, we ignore + if ( + modifierKey === "shift" && + isDOMElement(target) && + isTypableElement(target) + ) { + return null + } - const target = ev.target + return `${modifierKey}-${key}` + } // no modifier key here then we do not do anything while on input if (isDOMElement(target) && isTypableElement(target)) return null