mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-21 17:09:09 +01:00
Remove Escape from hotkeys
This commit is contained in:
@@ -4,10 +4,9 @@ import { capitalize } from '../lib/capitalize';
|
||||
import { debounce } from '../lib/debounce';
|
||||
import { useOsInfo } from './useOsInfo';
|
||||
|
||||
const HOLD_KEYS = ['Shift', 'CmdCtrl', 'Alt', 'Meta'];
|
||||
const HOLD_KEYS = ['Shift', 'Control', 'Command', 'Alt', 'Meta'];
|
||||
|
||||
export type HotkeyAction =
|
||||
| 'popup.close'
|
||||
| 'environmentEditor.toggle'
|
||||
| 'hotkeys.showHelp'
|
||||
| 'grpc_request.send'
|
||||
@@ -22,7 +21,6 @@ export type HotkeyAction =
|
||||
| 'urlBar.focus';
|
||||
|
||||
const hotkeys: Record<HotkeyAction, string[]> = {
|
||||
'popup.close': ['Escape'],
|
||||
'environmentEditor.toggle': ['CmdCtrl+Shift+e'],
|
||||
'grpc_request.send': ['CmdCtrl+Enter', 'CmdCtrl+r'],
|
||||
'hotkeys.showHelp': ['CmdCtrl+Shift+/'],
|
||||
@@ -38,7 +36,6 @@ const hotkeys: Record<HotkeyAction, string[]> = {
|
||||
};
|
||||
|
||||
const hotkeyLabels: Record<HotkeyAction, string> = {
|
||||
'popup.close': 'Close Dropdown',
|
||||
'environmentEditor.toggle': 'Edit Environments',
|
||||
'grpc_request.send': 'Send Message',
|
||||
'hotkeys.showHelp': 'Show Keyboard Shortcuts',
|
||||
@@ -83,15 +80,30 @@ export function useHotKey(
|
||||
}
|
||||
|
||||
const key = normalizeKey(e.key, os);
|
||||
|
||||
// Don't add hold keys
|
||||
if (HOLD_KEYS.includes(key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentKeys.current.add(key);
|
||||
|
||||
const currentKeysWithModifiers = new Set(currentKeys.current);
|
||||
if (e.altKey) currentKeysWithModifiers.add(normalizeKey('Alt', os));
|
||||
if (e.ctrlKey) currentKeysWithModifiers.add(normalizeKey('Control', os));
|
||||
if (e.metaKey) currentKeysWithModifiers.add(normalizeKey('Meta', os));
|
||||
if (e.shiftKey) currentKeysWithModifiers.add(normalizeKey('Shift', os));
|
||||
|
||||
for (const [hkAction, hkKeys] of Object.entries(hotkeys) as [HotkeyAction, string[]][]) {
|
||||
for (const hkKey of hkKeys) {
|
||||
if (hkAction !== action) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const keys = hkKey.split('+');
|
||||
if (
|
||||
keys.length === currentKeys.current.size &&
|
||||
keys.every((key) => currentKeys.current.has(key)) &&
|
||||
hkAction === action
|
||||
keys.length === currentKeysWithModifiers.size &&
|
||||
keys.every((key) => currentKeysWithModifiers.has(key))
|
||||
) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
@@ -112,7 +124,7 @@ export function useHotKey(
|
||||
// Clear all keys if no longer holding modifier
|
||||
// HACK: This is to get around the case of DOWN SHIFT -> DOWN : -> UP SHIFT -> UP ;
|
||||
// As you see, the ":" is not removed because it turned into ";" when shift was released
|
||||
const isHoldingModifier = HOLD_KEYS.some((k) => currentKeys.current.has(k));
|
||||
const isHoldingModifier = e.altKey || e.ctrlKey || e.metaKey || e.shiftKey;
|
||||
if (!isHoldingModifier) {
|
||||
currentKeys.current.clear();
|
||||
}
|
||||
|
||||
@@ -85,6 +85,5 @@ export function useIntrospectGraphQL(baseRequest: HttpRequest) {
|
||||
[introspection],
|
||||
);
|
||||
|
||||
console.log('SCHEMA', introspection);
|
||||
return { schema, isLoading, error, refetch };
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ import { trackEvent } from '../lib/analytics';
|
||||
import type { HttpResponse } from '../lib/models';
|
||||
import { getHttpRequest } from '../lib/store';
|
||||
import { useActiveCookieJar } from './useActiveCookieJar';
|
||||
import { useActiveEnvironmentId } from './useActiveEnvironmentId';
|
||||
import { useActiveEnvironment } from './useActiveEnvironment';
|
||||
import { useAlert } from './useAlert';
|
||||
|
||||
export function useSendAnyRequest(options: { download?: boolean } = {}) {
|
||||
const environmentId = useActiveEnvironmentId();
|
||||
const environment = useActiveEnvironment();
|
||||
const alert = useAlert();
|
||||
const { activeCookieJar } = useActiveCookieJar();
|
||||
return useMutation<HttpResponse | null, string, string | null>({
|
||||
@@ -33,7 +33,7 @@ export function useSendAnyRequest(options: { download?: boolean } = {}) {
|
||||
|
||||
return invoke('cmd_send_http_request', {
|
||||
requestId: id,
|
||||
environmentId,
|
||||
environmentId: environment?.id,
|
||||
downloadDir: downloadDir,
|
||||
cookieJarId: activeCookieJar?.id,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user