Skip to content

Commit 885e0ad

Browse files
authored
fix: Restored the up/down arrow key navigation for the file changes list (#482)
Restored the up/down arrow key navigation for the file changes list Make up/down in changes panel work with permissions listeners Remove unused useTaskKeyboardNavigation Update KeyboardShortcutsSheet.tsx Update keyboard-shortcuts.ts Update ChangesPanel.tsx
1 parent 6fb9493 commit 885e0ad

4 files changed

Lines changed: 63 additions & 91 deletions

File tree

apps/array/src/renderer/components/KeyboardShortcutsSheet.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export function KeyboardShortcutsSheet({
2323
"general",
2424
"navigation",
2525
"panels",
26-
"taskList",
2726
"editor",
2827
];
2928

apps/array/src/renderer/constants/keyboard-shortcuts.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,12 @@ export const SHORTCUTS = {
1111
SWITCH_TAB: "mod+1,mod+2,mod+3,mod+4,mod+5,mod+6,mod+7,mod+8,mod+9",
1212
OPEN_IN_EDITOR: "mod+o",
1313
COPY_PATH: "mod+shift+c",
14-
TASK_NAV_UP: "up",
15-
TASK_NAV_DOWN: "down",
16-
TASK_SELECT: "enter",
1714
TASK_REFRESH: "mod+r",
1815
BLUR: "escape",
1916
SUBMIT_BLUR: "mod+enter",
2017
} as const;
2118

22-
export type ShortcutCategory =
23-
| "general"
24-
| "navigation"
25-
| "panels"
26-
| "editor"
27-
| "taskList";
19+
export type ShortcutCategory = "general" | "navigation" | "panels" | "editor";
2820

2921
export interface KeyboardShortcut {
3022
id: string;
@@ -117,20 +109,6 @@ export const KEYBOARD_SHORTCUTS: KeyboardShortcut[] = [
117109
category: "panels",
118110
context: "Task detail",
119111
},
120-
{
121-
id: "task-nav-up",
122-
keys: SHORTCUTS.TASK_NAV_UP,
123-
description: "Navigate up",
124-
category: "taskList",
125-
context: "Task list",
126-
},
127-
{
128-
id: "task-nav-down",
129-
keys: SHORTCUTS.TASK_NAV_DOWN,
130-
description: "Navigate down",
131-
category: "taskList",
132-
context: "Task list",
133-
},
134112
{
135113
id: "editor-bold",
136114
keys: "mod+b",
@@ -166,7 +144,6 @@ export const CATEGORY_LABELS: Record<ShortcutCategory, string> = {
166144
navigation: "Navigation",
167145
panels: "Panels & Tabs",
168146
editor: "Editor",
169-
taskList: "Task List",
170147
};
171148

172149
export function getShortcutsByCategory(): Record<
@@ -178,7 +155,6 @@ export function getShortcutsByCategory(): Record<
178155
navigation: [],
179156
panels: [],
180157
editor: [],
181-
taskList: [],
182158
};
183159
for (const shortcut of KEYBOARD_SHORTCUTS) {
184160
grouped[shortcut.category].push(shortcut);

apps/array/src/renderer/features/task-detail/components/ChangesPanel.tsx

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { FileIcon } from "@components/ui/FileIcon";
22
import { PanelMessage } from "@components/ui/PanelMessage";
33
import { isDiffTabActiveInTree, usePanelLayoutStore } from "@features/panels";
4+
import { usePendingPermissionsForTask } from "@features/sessions/stores/sessionStore";
45
import { GitActionsBar } from "@features/task-detail/components/GitActionsBar";
56
import { useTaskData } from "@features/task-detail/hooks/useTaskData";
67
import {
78
ArrowCounterClockwiseIcon,
9+
CaretDownIcon,
10+
CaretUpIcon,
811
CodeIcon,
912
CopyIcon,
1013
FilePlus,
@@ -24,7 +27,8 @@ import { useExternalAppsStore } from "@stores/externalAppsStore";
2427
import { useQuery, useQueryClient } from "@tanstack/react-query";
2528
import { showMessageBox } from "@utils/dialog";
2629
import { handleExternalAppAction } from "@utils/handleExternalAppAction";
27-
import { useState } from "react";
30+
import { useCallback, useState } from "react";
31+
import { useHotkeys } from "react-hotkeys-hook";
2832
import {
2933
selectWorktreePath,
3034
useWorkspaceStore,
@@ -350,6 +354,9 @@ export function ChangesPanel({ taskId, task }: ChangesPanelProps) {
350354
const worktreePath = useWorkspaceStore(selectWorktreePath(taskId));
351355
const repoPath = worktreePath ?? taskData.repoPath;
352356
const layout = usePanelLayoutStore((state) => state.getLayout(taskId));
357+
const openDiff = usePanelLayoutStore((state) => state.openDiff);
358+
const pendingPermissions = usePendingPermissionsForTask(taskId);
359+
const hasPendingPermissions = pendingPermissions.size > 0;
353360

354361
const { data: changedFiles = [], isLoading } = useQuery({
355362
queryKey: ["changed-files-head", repoPath],
@@ -362,6 +369,50 @@ export function ChangesPanel({ taskId, task }: ChangesPanelProps) {
362369
refetchOnWindowFocus: true,
363370
});
364371

372+
const getActiveIndex = useCallback((): number => {
373+
if (!layout) return -1;
374+
return changedFiles.findIndex((file) =>
375+
isDiffTabActiveInTree(layout.panelTree, file.path, file.status),
376+
);
377+
}, [layout, changedFiles]);
378+
379+
const handleKeyNavigation = useCallback(
380+
(direction: "up" | "down") => {
381+
if (changedFiles.length === 0) return;
382+
383+
const currentIndex = getActiveIndex();
384+
const startIndex =
385+
currentIndex === -1
386+
? direction === "down"
387+
? -1
388+
: changedFiles.length
389+
: currentIndex;
390+
const newIndex =
391+
direction === "up"
392+
? Math.max(0, startIndex - 1)
393+
: Math.min(changedFiles.length - 1, startIndex + 1);
394+
395+
const file = changedFiles[newIndex];
396+
if (file) {
397+
openDiff(taskId, file.path, file.status);
398+
}
399+
},
400+
[changedFiles, getActiveIndex, openDiff, taskId],
401+
);
402+
403+
useHotkeys(
404+
"up",
405+
() => handleKeyNavigation("up"),
406+
{ enabled: !hasPendingPermissions },
407+
[handleKeyNavigation, hasPendingPermissions],
408+
);
409+
useHotkeys(
410+
"down",
411+
() => handleKeyNavigation("down"),
412+
{ enabled: !hasPendingPermissions },
413+
[handleKeyNavigation, hasPendingPermissions],
414+
);
415+
365416
const isFileActive = (file: ChangedFile): boolean => {
366417
if (!layout) return false;
367418
return isDiffTabActiveInTree(layout.panelTree, file.path, file.status);
@@ -404,6 +455,16 @@ export function ChangesPanel({ taskId, task }: ChangesPanelProps) {
404455
isActive={isFileActive(file)}
405456
/>
406457
))}
458+
<Flex align="center" justify="center" gap="1" py="2">
459+
<CaretUpIcon size={12} color="var(--gray-10)" />
460+
<Text size="1" className="text-gray-10">
461+
/
462+
</Text>
463+
<CaretDownIcon size={12} color="var(--gray-10)" />
464+
<Text size="1" className="text-gray-10" ml="1">
465+
to switch files
466+
</Text>
467+
</Flex>
407468
</Flex>
408469
</Box>
409470
<GitActionsBar taskId={taskId} repoPath={repoPath} hasChanges={true} />

apps/array/src/renderer/features/task-list/hooks/useTaskKeyboardNavigation.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)