Skip to content

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

feat: shift based keyboard shortcuts and save as action

Andrew Bastin08fe4ae71f9f
diff --git a/components/http/Request.vue b/components/http/Request.vue
index ecfd0613d..2e5801dd8 100644
--- a/components/http/Request.vue
+++ b/components/http/Request.vue
@@ -413,6 +413,10 @@ export default defineComponent({
defineActionHandler("request.method.next", cycleDownMethod)
defineActionHandler("request.method.prev", cycleUpMethod)
defineActionHandler("request.save", saveRequest)
+ defineActionHandler(
+ "request.save-as",
+ () => (showSaveRequestModal.value = true)
+ )
defineActionHandler("request.method.get", () => updateMethod("GET"))
defineActionHandler("request.method.post", () => updateMethod("POST"))
defineActionHandler("request.method.put", () => updateMethod("PUT"))
diff --git a/helpers/actions.ts b/helpers/actions.ts
index 68ae2721b..0548f2021 100644
--- a/helpers/actions.ts
+++ b/helpers/actions.ts
@@ -10,6 +10,7 @@ export type HoppAction =
| "request.reset" // Clear request data
| "request.copy-link" // Copy Request Link
| "request.save" // Save to Collections
+ | "request.save-as" // Save As
| "request.method.next" // Select Next Method
| "request.method.prev" // Select Previous Method
| "request.method.get" // Select GET Method
diff --git a/helpers/keybindings.ts b/helpers/keybindings.ts
index 9ff28d08b..3d4a9bfef 100644
--- a/helpers/keybindings.ts
+++ b/helpers/keybindings.ts
@@ -14,7 +14,7 @@ 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"
+type ModifierKeys = "ctrl" | "alt" | "ctrl-shift" | "alt-shift"
/* eslint-disable prettier/prettier */
// prettier-ignore
@@ -40,6 +40,7 @@ export const bindings: {
"ctrl-i": "request.reset",
"ctrl-c": "request.copy-link",
"ctrl-s": "request.save",
+ "ctrl-shift-s": "request.save-as",
"alt-up": "request.method.next",
"alt-down": "request.method.prev",
"alt-g": "request.method.get",
@@ -136,16 +137,16 @@ function getPressedKey(ev: KeyboardEvent): Key | null {
}
function getActiveModifier(ev: KeyboardEvent): ModifierKeys | null {
- // Just ignore everything if Shift is pressed (for now)
- if (ev.shiftKey) return 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 "ctrl"
- else if (!isAppleDevice() && ev.ctrlKey) return "ctrl"
+ if (isAppleDevice() && ev.metaKey) return isShiftKey ? "ctrl-shift" : "ctrl"
+ else if (!isAppleDevice() && ev.ctrlKey)
+ return isShiftKey ? "ctrl-shift" : "ctrl"
// Test for Alt key
- if (ev.altKey) return "alt"
+ if (ev.altKey) return isShiftKey ? "alt-shift" : "alt"
return null
}