mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-19 15:21:23 +02:00
Hotkeys for request switcher
This commit is contained in:
@@ -5,6 +5,7 @@ import { useActiveEnvironmentId } from '../hooks/useActiveEnvironmentId';
|
|||||||
import { useActiveRequest } from '../hooks/useActiveRequest';
|
import { useActiveRequest } from '../hooks/useActiveRequest';
|
||||||
import { useActiveWorkspaceId } from '../hooks/useActiveWorkspaceId';
|
import { useActiveWorkspaceId } from '../hooks/useActiveWorkspaceId';
|
||||||
import { useAppRoutes } from '../hooks/useAppRoutes';
|
import { useAppRoutes } from '../hooks/useAppRoutes';
|
||||||
|
import { useHotKey } from '../hooks/useHotKey';
|
||||||
import { useRecentRequests } from '../hooks/useRecentRequests';
|
import { useRecentRequests } from '../hooks/useRecentRequests';
|
||||||
import { useRequests } from '../hooks/useRequests';
|
import { useRequests } from '../hooks/useRequests';
|
||||||
import { fallbackRequestName } from '../lib/fallbackRequestName';
|
import { fallbackRequestName } from '../lib/fallbackRequestName';
|
||||||
@@ -33,25 +34,19 @@ export function RecentRequestsDropdown({ className }: Pick<ButtonProps, 'classNa
|
|||||||
|
|
||||||
// Handle key-up
|
// Handle key-up
|
||||||
useKeyPressEvent('Control', undefined, () => {
|
useKeyPressEvent('Control', undefined, () => {
|
||||||
|
if (!dropdownRef.current?.isOpen) return;
|
||||||
dropdownRef.current?.select?.();
|
dropdownRef.current?.select?.();
|
||||||
});
|
});
|
||||||
|
|
||||||
useKey(
|
useHotKey('requestSwitcher.prev', () => {
|
||||||
'Tab',
|
if (!dropdownRef.current?.isOpen) dropdownRef.current?.open(1);
|
||||||
(e) => {
|
dropdownRef.current?.next?.();
|
||||||
if (!e.ctrlKey || recentRequestIds.length === 0) return;
|
});
|
||||||
|
|
||||||
if (!dropdownRef.current?.isOpen) {
|
useHotKey('requestSwitcher.next', () => {
|
||||||
dropdownRef.current?.open(e.shiftKey ? -1 : 1);
|
if (!dropdownRef.current?.isOpen) dropdownRef.current?.open(-1);
|
||||||
return;
|
dropdownRef.current?.prev?.();
|
||||||
}
|
});
|
||||||
|
|
||||||
if (e.shiftKey) dropdownRef.current?.prev?.();
|
|
||||||
else dropdownRef.current?.next?.();
|
|
||||||
},
|
|
||||||
undefined,
|
|
||||||
[recentRequestIds.length],
|
|
||||||
);
|
|
||||||
|
|
||||||
const items = useMemo<DropdownItem[]>(() => {
|
const items = useMemo<DropdownItem[]>(() => {
|
||||||
if (activeWorkspaceId === null) return [];
|
if (activeWorkspaceId === null) return [];
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { useRef } from 'react';
|
|||||||
import { useAppVersion } from '../hooks/useAppVersion';
|
import { useAppVersion } from '../hooks/useAppVersion';
|
||||||
import { useExportData } from '../hooks/useExportData';
|
import { useExportData } from '../hooks/useExportData';
|
||||||
import { useImportData } from '../hooks/useImportData';
|
import { useImportData } from '../hooks/useImportData';
|
||||||
import { useTheme } from '../hooks/useTheme';
|
|
||||||
import { useUpdateMode } from '../hooks/useUpdateMode';
|
import { useUpdateMode } from '../hooks/useUpdateMode';
|
||||||
import { Button } from './core/Button';
|
import { Button } from './core/Button';
|
||||||
import type { DropdownRef } from './core/Dropdown';
|
import type { DropdownRef } from './core/Dropdown';
|
||||||
@@ -18,7 +17,6 @@ import { SettingsDialog } from './SettingsDialog';
|
|||||||
export function SettingsDropdown() {
|
export function SettingsDropdown() {
|
||||||
const importData = useImportData();
|
const importData = useImportData();
|
||||||
const exportData = useExportData();
|
const exportData = useExportData();
|
||||||
const { appearance, toggleAppearance } = useTheme();
|
|
||||||
const appVersion = useAppVersion();
|
const appVersion = useAppVersion();
|
||||||
const [updateMode, setUpdateMode] = useUpdateMode();
|
const [updateMode, setUpdateMode] = useUpdateMode();
|
||||||
const dropdownRef = useRef<DropdownRef>(null);
|
const dropdownRef = useRef<DropdownRef>(null);
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ export type HotkeyAction =
|
|||||||
| 'urlBar.focus'
|
| 'urlBar.focus'
|
||||||
| 'environmentEditor.toggle'
|
| 'environmentEditor.toggle'
|
||||||
| 'hotkeys.showHelp'
|
| 'hotkeys.showHelp'
|
||||||
|
| 'requestSwitcher.prev'
|
||||||
|
| 'requestSwitcher.next'
|
||||||
| 'settings.show';
|
| 'settings.show';
|
||||||
|
|
||||||
const hotkeys: Record<HotkeyAction, string[]> = {
|
const hotkeys: Record<HotkeyAction, string[]> = {
|
||||||
@@ -24,6 +26,8 @@ const hotkeys: Record<HotkeyAction, string[]> = {
|
|||||||
'environmentEditor.toggle': ['CmdCtrl+e'],
|
'environmentEditor.toggle': ['CmdCtrl+e'],
|
||||||
'hotkeys.showHelp': ['CmdCtrl+/'],
|
'hotkeys.showHelp': ['CmdCtrl+/'],
|
||||||
'settings.show': ['CmdCtrl+,'],
|
'settings.show': ['CmdCtrl+,'],
|
||||||
|
'requestSwitcher.prev': ['Control+Tab'],
|
||||||
|
'requestSwitcher.next': ['Control+Shift+Tab'],
|
||||||
};
|
};
|
||||||
|
|
||||||
const hotkeyLabels: Record<HotkeyAction, string> = {
|
const hotkeyLabels: Record<HotkeyAction, string> = {
|
||||||
@@ -35,6 +39,8 @@ const hotkeyLabels: Record<HotkeyAction, string> = {
|
|||||||
'urlBar.focus': 'Focus URL',
|
'urlBar.focus': 'Focus URL',
|
||||||
'environmentEditor.toggle': 'Edit Environments',
|
'environmentEditor.toggle': 'Edit Environments',
|
||||||
'hotkeys.showHelp': 'Show Keyboard Shortcuts',
|
'hotkeys.showHelp': 'Show Keyboard Shortcuts',
|
||||||
|
'requestSwitcher.prev': 'Go To Next Request',
|
||||||
|
'requestSwitcher.next': 'Go To Previous Request',
|
||||||
'settings.show': 'Open Settings',
|
'settings.show': 'Open Settings',
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -136,6 +142,8 @@ export function useFormattedHotkey(action: HotkeyAction | null): string | null {
|
|||||||
labelParts.push('⌃');
|
labelParts.push('⌃');
|
||||||
} else if (p === 'Enter') {
|
} else if (p === 'Enter') {
|
||||||
labelParts.push('↩');
|
labelParts.push('↩');
|
||||||
|
} else if (p === 'Tab') {
|
||||||
|
labelParts.push('⇥');
|
||||||
} else {
|
} else {
|
||||||
labelParts.push(p.toUpperCase());
|
labelParts.push(p.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user