feat: shift based keyboard shortcuts and save as action
This commit is contained in:
@@ -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"))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user