Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix: keybinding modifier issue (#3163)

Anwarul Islam51efb35aa6ee
diff --git a/packages/hoppscotch-common/src/helpers/keybindings.ts b/packages/hoppscotch-common/src/helpers/keybindings.ts
index f2f62f128..0f703ebb7 100644
--- a/packages/hoppscotch-common/src/helpers/keybindings.ts
+++ b/packages/hoppscotch-common/src/helpers/keybindings.ts
@@ -14,7 +14,13 @@ let keybindingsEnabled = true
* Alt is also regarded as macOS OPTION (⌥) key
* Ctrl is also regarded as macOS COMMAND (⌘) key (NOTE: this differs from HTML Keyboard spec where COMMAND is Meta key!)
*/
-type ModifierKeys = "ctrl" | "alt" | "ctrl-shift" | "alt-shift"
+type ModifierKeys =
+ | "ctrl"
+ | "alt"
+ | "ctrl-shift"
+ | "alt-shift"
+ | "ctrl-alt"
+ | "ctrl-alt-shift"
/* eslint-disable prettier/prettier */
// prettier-ignore
@@ -143,18 +149,19 @@ function getPressedKey(ev: KeyboardEvent): Key | null {
}
function getActiveModifier(ev: KeyboardEvent): ModifierKeys | null {
- const isShiftKey = ev.shiftKey
-
- // We only allow one modifier key to be pressed (for now)
- // Control key (+ Command) gets priority and if Alt is also pressed, it is ignored
- if (isAppleDevice() && ev.metaKey) return isShiftKey ? "ctrl-shift" : "ctrl"
- else if (!isAppleDevice() && ev.ctrlKey)
- return isShiftKey ? "ctrl-shift" : "ctrl"
+ const modifierKeys = {
+ ctrl: isAppleDevice() ? ev.metaKey : ev.ctrlKey,
+ alt: ev.altKey,
+ shift: ev.shiftKey,
+ }
- // Test for Alt key
- if (ev.altKey) return isShiftKey ? "alt-shift" : "alt"
+ // active modifier: ctrl | alt | ctrl-alt | ctrl-shift | ctrl-alt-shift | alt-shift
+ // modiferKeys object's keys are sorted to match the above order
+ const activeModifier = Object.keys(modifierKeys)
+ .filter((key) => modifierKeys[key as keyof typeof modifierKeys])
+ .join("-")
- return null
+ return activeModifier === "" ? null : (activeModifier as ModifierKeys)
}
/**