Skip to content

Commit 9ad6588

Browse files
authored
app: allow navigating projects with keybinds (anomalyco#18502)
1 parent fb6bf0b commit 9ad6588

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

packages/app/src/i18n/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export const dict = {
2323

2424
"command.sidebar.toggle": "Toggle sidebar",
2525
"command.project.open": "Open project",
26+
"command.project.previous": "Previous project",
27+
"command.project.next": "Next project",
2628
"command.provider.connect": "Connect provider",
2729
"command.server.switch": "Switch server",
2830
"command.settings.open": "Open settings",

packages/app/src/pages/layout.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,26 @@ export default function Layout(props: ParentProps) {
936936
navigateToSession(session)
937937
}
938938

939+
function navigateProjectByOffset(offset: number) {
940+
const projects = layout.projects.list()
941+
if (projects.length === 0) return
942+
943+
const current = currentProject()?.worktree
944+
const fallback = currentDir() ? projectRoot(currentDir()) : undefined
945+
const active = current ?? fallback
946+
const index = active ? projects.findIndex((project) => project.worktree === active) : -1
947+
948+
const target =
949+
index === -1
950+
? offset > 0
951+
? projects[0]
952+
: projects[projects.length - 1]
953+
: projects[(index + offset + projects.length) % projects.length]
954+
if (!target) return
955+
956+
openProject(target.worktree)
957+
}
958+
939959
function navigateSessionByUnseen(offset: number) {
940960
const sessions = currentSessions()
941961
if (sessions.length === 0) return
@@ -1002,6 +1022,20 @@ export default function Layout(props: ParentProps) {
10021022
keybind: "mod+o",
10031023
onSelect: () => chooseProject(),
10041024
},
1025+
{
1026+
id: "project.previous",
1027+
title: language.t("command.project.previous"),
1028+
category: language.t("command.category.project"),
1029+
keybind: "mod+alt+arrowup",
1030+
onSelect: () => navigateProjectByOffset(-1),
1031+
},
1032+
{
1033+
id: "project.next",
1034+
title: language.t("command.project.next"),
1035+
category: language.t("command.category.project"),
1036+
keybind: "mod+alt+arrowdown",
1037+
onSelect: () => navigateProjectByOffset(1),
1038+
},
10051039
{
10061040
id: "provider.connect",
10071041
title: language.t("command.provider.connect"),

0 commit comments

Comments
 (0)