mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-18 06:49:50 +02:00
Fix hotkeys getting stuck on cmd+tab
This commit is contained in:
@@ -55,6 +55,7 @@ export function Sidebar({ className }: Props) {
|
|||||||
const { hidden } = useSidebarHidden();
|
const { hidden } = useSidebarHidden();
|
||||||
const sidebarRef = useRef<HTMLLIElement>(null);
|
const sidebarRef = useRef<HTMLLIElement>(null);
|
||||||
const activeRequestId = useActiveRequestId();
|
const activeRequestId = useActiveRequestId();
|
||||||
|
const duplicateRequest = useDuplicateRequest({ id: activeRequestId ?? '', navigateAfter: true });
|
||||||
const activeEnvironmentId = useActiveEnvironmentId();
|
const activeEnvironmentId = useActiveEnvironmentId();
|
||||||
const requests = useRequests();
|
const requests = useRequests();
|
||||||
const folders = useFolders();
|
const folders = useFolders();
|
||||||
@@ -75,6 +76,8 @@ export function Sidebar({ className }: Props) {
|
|||||||
namespace: NAMESPACE_NO_SYNC,
|
namespace: NAMESPACE_NO_SYNC,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useHotkey('request.duplicate', () => duplicateRequest.mutate());
|
||||||
|
|
||||||
const isCollapsed = useCallback(
|
const isCollapsed = useCallback(
|
||||||
(id: string) => collapsed.value?.[id] ?? false,
|
(id: string) => collapsed.value?.[id] ?? false,
|
||||||
[collapsed.value],
|
[collapsed.value],
|
||||||
@@ -581,7 +584,6 @@ const SidebarItem = forwardRef(function SidebarItem(
|
|||||||
const handleContextMenu = useCallback((e: React.MouseEvent<HTMLElement>) => {
|
const handleContextMenu = useCallback((e: React.MouseEvent<HTMLElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
console.log('CONTEXT MENU');
|
|
||||||
setShowContextMenu({ x: e.clientX, y: e.clientY });
|
setShowContextMenu({ x: e.clientX, y: e.clientY });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -647,7 +649,10 @@ const SidebarItem = forwardRef(function SidebarItem(
|
|||||||
label: 'Duplicate',
|
label: 'Duplicate',
|
||||||
hotkeyAction: 'request.duplicate',
|
hotkeyAction: 'request.duplicate',
|
||||||
leftSlot: <Icon icon="copy" />,
|
leftSlot: <Icon icon="copy" />,
|
||||||
onSelect: () => duplicateRequest.mutate(),
|
onSelect: () => {
|
||||||
|
console.log('DUPLICATE');
|
||||||
|
duplicateRequest.mutate();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'deleteRequest',
|
key: 'deleteRequest',
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function HotKey({ action }: Props) {
|
export function HotKey({ action }: Props) {
|
||||||
const osinfo = useOsInfo();
|
const osInfo = useOsInfo();
|
||||||
const label = useFormattedHotkey(action);
|
const label = useFormattedHotkey(action);
|
||||||
if (label === null || osinfo == null) {
|
if (label === null || osInfo == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { OsType } from '@tauri-apps/api/os';
|
import type { OsType } from '@tauri-apps/api/os';
|
||||||
import { useEffect, useRef } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
|
import { debounce } from '../lib/debounce';
|
||||||
import { useOsInfo } from './useOsInfo';
|
import { useOsInfo } from './useOsInfo';
|
||||||
|
|
||||||
export type HotkeyAction =
|
export type HotkeyAction =
|
||||||
@@ -40,8 +41,12 @@ export function useAnyHotkey(callback: (action: HotkeyAction, e: KeyboardEvent)
|
|||||||
}, [callback]);
|
}, [callback]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// Sometimes the keyup event doesn't fire, so we clear the keys after a timeout
|
||||||
|
const clearCurrentKeys = debounce(() => currentKeys.current.clear(), 1000);
|
||||||
|
|
||||||
const down = (e: KeyboardEvent) => {
|
const down = (e: KeyboardEvent) => {
|
||||||
currentKeys.current.add(normalizeKey(e.key, os));
|
currentKeys.current.add(normalizeKey(e.key, os));
|
||||||
|
|
||||||
for (const [hkAction, hkKeys] of Object.entries(hotkeys) as [HotkeyAction, string[]][]) {
|
for (const [hkAction, hkKeys] of Object.entries(hotkeys) as [HotkeyAction, string[]][]) {
|
||||||
for (const hkKey of hkKeys) {
|
for (const hkKey of hkKeys) {
|
||||||
const keys = hkKey.split('+');
|
const keys = hkKey.split('+');
|
||||||
@@ -56,6 +61,7 @@ export function useAnyHotkey(callback: (action: HotkeyAction, e: KeyboardEvent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
clearCurrentKeys();
|
||||||
};
|
};
|
||||||
const up = (e: KeyboardEvent) => {
|
const up = (e: KeyboardEvent) => {
|
||||||
currentKeys.current.delete(normalizeKey(e.key, os));
|
currentKeys.current.delete(normalizeKey(e.key, os));
|
||||||
|
|||||||
Reference in New Issue
Block a user