From 5a79c3ba2aac215302e861e5da3551faef8e94a9 Mon Sep 17 00:00:00 2001 From: Shreyas Date: Wed, 9 Jul 2025 16:33:12 +0530 Subject: [PATCH] feat(desktop): tab shortcuts discoverability (#5229) This adds tab navigation shortcuts to the shortcuts help dialog for desktop users and conditionally shows them only in desktop mode. The shortcuts help now includes a "Tabs" section with all available tab management shortcuts, but only displays them when running in desktop kernel mode to avoid confusing web users with non-functional shortcuts. Closes FE-917 The desktop app already had functional tab navigation shortcuts, but they weren't documented in the app's shortcuts help dialog (accessible via `?` or `Cmd/Ctrl+/`). This made the shortcuts less discoverable for users who wanted to learn about available keyboard controls. --- packages/hoppscotch-common/locales/en.json | 10 +++++ .../src/helpers/shortcuts.ts | 45 ++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/packages/hoppscotch-common/locales/en.json b/packages/hoppscotch-common/locales/en.json index 885357ad..ee67abf9 100644 --- a/packages/hoppscotch-common/locales/en.json +++ b/packages/hoppscotch-common/locales/en.json @@ -1114,6 +1114,16 @@ "download": "Download response as file", "title": "Response" }, + "tabs": { + "title": "Tabs", + "new_tab": "New Tab", + "close_tab": "Close Tab", + "reopen_tab": "Reopen Closed Tab", + "next_tab": "Next Tab", + "previous_tab": "Previous Tab", + "first_tab": "Switch to First Tab", + "last_tab": "Switch to Last Tab" + }, "theme": { "black": "Switch theme to Black Mode", "dark": "Switch theme to Dark Mode", diff --git a/packages/hoppscotch-common/src/helpers/shortcuts.ts b/packages/hoppscotch-common/src/helpers/shortcuts.ts index 573cb2a6..35ab8a2f 100644 --- a/packages/hoppscotch-common/src/helpers/shortcuts.ts +++ b/packages/hoppscotch-common/src/helpers/shortcuts.ts @@ -1,4 +1,5 @@ import { getPlatformAlternateKey, getPlatformSpecialKey } from "./platformutils" +import { getKernelMode } from "@hoppscotch/kernel" export type ShortcutDef = { label: string @@ -7,8 +8,11 @@ export type ShortcutDef = { } export function getShortcuts(t: (x: string) => string): ShortcutDef[] { - // General - return [ + const kernelMode = getKernelMode() + const isDesktop = kernelMode === "desktop" + + const baseShortcuts: ShortcutDef[] = [ + // General { label: t("shortcut.general.help_menu"), keys: ["?"], @@ -143,4 +147,41 @@ export function getShortcuts(t: (x: string) => string): ShortcutDef[] { section: t("shortcut.miscellaneous.title"), }, ] + + // Desktop-only shortcuts + const desktopShortcuts: ShortcutDef[] = [ + { + keys: [getPlatformSpecialKey(), "T"], + label: t("shortcut.tabs.new_tab"), + section: t("shortcut.tabs.title"), + }, + { + keys: [getPlatformSpecialKey(), "W"], + label: t("shortcut.tabs.close_tab"), + section: t("shortcut.tabs.title"), + }, + { + keys: [getPlatformSpecialKey(), getPlatformAlternateKey(), "→"], + label: t("shortcut.tabs.next_tab"), + section: t("shortcut.tabs.title"), + }, + { + keys: [getPlatformSpecialKey(), getPlatformAlternateKey(), "←"], + label: t("shortcut.tabs.previous_tab"), + section: t("shortcut.tabs.title"), + }, + { + keys: [getPlatformSpecialKey(), getPlatformAlternateKey(), "9"], + label: t("shortcut.tabs.first_tab"), + section: t("shortcut.tabs.title"), + }, + { + keys: [getPlatformSpecialKey(), getPlatformAlternateKey(), "0"], + label: t("shortcut.tabs.last_tab"), + section: t("shortcut.tabs.title"), + }, + ] + + // Return base shortcuts + desktop shortcuts only if in desktop mode + return isDesktop ? [...baseShortcuts, ...desktopShortcuts] : baseShortcuts }