Improve Dropdown selection handling

This commit is contained in:
Gregory Schier
2025-01-11 08:15:45 -08:00
parent 3b56f4e142
commit 3d3ff2824f
3 changed files with 75 additions and 59 deletions

View File

@@ -22,8 +22,7 @@ interface Props {
export function RecentRequestsDropdown({ className }: Props) {
const activeRequest = useActiveRequest();
const dropdownRef = useRef<DropdownRef>(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 (
<Dropdown ref={dropdownRef} items={items}>
<Button
data-tauri-drag-region
size="sm"
hotkeyAction="request_switcher.toggle"
className={classNames(