From 3d3ff2824fdc19612ef41d7692e2e0d19d35198c Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sat, 11 Jan 2025 08:15:45 -0800 Subject: [PATCH] Improve Dropdown selection handling --- src-web/components/RecentRequestsDropdown.tsx | 13 +- src-web/components/core/Dropdown.tsx | 119 ++++++++++-------- src-web/hooks/useStateWithDeps.ts | 2 +- 3 files changed, 75 insertions(+), 59 deletions(-) diff --git a/src-web/components/RecentRequestsDropdown.tsx b/src-web/components/RecentRequestsDropdown.tsx index 00dce15a..087ae330 100644 --- a/src-web/components/RecentRequestsDropdown.tsx +++ b/src-web/components/RecentRequestsDropdown.tsx @@ -22,8 +22,7 @@ interface Props { export function RecentRequestsDropdown({ className }: Props) { const activeRequest = useActiveRequest(); const dropdownRef = useRef(null); - const [allRecentRequestIds] = useRecentRequests(); - const recentRequestIds = useMemo(() => allRecentRequestIds.slice(1), [allRecentRequestIds]); + const [recentRequestIds] = useRecentRequests(); // Handle key-up useKeyPressEvent('Control', undefined, () => { @@ -32,8 +31,13 @@ export function RecentRequestsDropdown({ className }: Props) { }); useHotKey('request_switcher.prev', () => { - if (!dropdownRef.current?.isOpen) dropdownRef.current?.open(); - dropdownRef.current?.next?.(); + if (!dropdownRef.current?.isOpen) { + dropdownRef.current?.open(); + // Select the second because the first is the current request + dropdownRef.current?.next?.(2); + } else { + dropdownRef.current?.next?.(); + } }); useHotKey('request_switcher.next', () => { @@ -83,7 +87,6 @@ export function RecentRequestsDropdown({ className }: Props) { return (