Skip to content

Commit 3992e2a

Browse files
authored
feat(app): add ctrl/cmd+number keybinds to switch projects (anomalyco#26280)
1 parent ea6eabe commit 3992e2a

5 files changed

Lines changed: 36 additions & 8 deletions

File tree

packages/app/src/components/dialog-select-file.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function createCommandEntries(props: {
107107
const allowed = createMemo(() => {
108108
if (props.filesOnly()) return []
109109
return props.command.options.filter(
110-
(option) => !option.disabled && !option.id.startsWith("suggested.") && option.id !== "file.open",
110+
(option) => !option.disabled && !option.hidden && !option.id.startsWith("suggested.") && option.id !== "file.open",
111111
)
112112
})
113113

packages/app/src/components/settings-keybinds.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ function listFor(command: CommandContext, map: KeybindMap, palette: string) {
123123

124124
for (const opt of command.catalog) {
125125
if (opt.id.startsWith("suggested.")) continue
126+
if (opt.hidden) continue
126127
out.set(opt.id, { title: opt.title, group: groupFor(opt.id) })
127128
}
128129

129130
for (const opt of command.options) {
130131
if (opt.id.startsWith("suggested.")) continue
132+
if (opt.hidden) continue
131133
out.set(opt.id, { title: opt.title, group: groupFor(opt.id) })
132134
}
133135

packages/app/src/context/command.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export interface CommandOption {
8181
slash?: string
8282
suggested?: boolean
8383
disabled?: boolean
84+
hidden?: boolean
8485
onSelect?: (source?: "palette" | "keybind" | "slash") => void
8586
onHighlight?: () => (() => void) | void
8687
}
@@ -93,6 +94,7 @@ export type CommandCatalogItem = {
9394
category?: string
9495
keybind?: KeybindConfig
9596
slash?: string
97+
hidden?: boolean
9698
}
9799

98100
export type CommandRegistration = {
@@ -279,13 +281,14 @@ export const { use: useCommand, provider: CommandProvider } = createSimpleContex
279281
setCatalog(
280282
registered().reduce((acc, opt) => {
281283
const id = actionId(opt.id)
282-
acc[id] = {
283-
title: opt.title,
284-
description: opt.description,
285-
category: opt.category,
286-
keybind: opt.keybind,
287-
slash: opt.slash,
288-
}
284+
if (opt.title)
285+
acc[id] = {
286+
title: opt.title,
287+
description: opt.description,
288+
category: opt.category,
289+
keybind: opt.keybind,
290+
slash: opt.slash,
291+
}
289292
return acc
290293
}, {} as CommandCatalog),
291294
)

packages/app/src/i18n/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const dict = {
2525
"command.project.open": "Open project",
2626
"command.project.previous": "Previous project",
2727
"command.project.next": "Next project",
28+
"command.project.index": "Switch to project {{index}}",
2829
"command.provider.connect": "Connect provider",
2930
"command.server.switch": "Switch server",
3031
"command.settings.open": "Open settings",

packages/app/src/pages/layout.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,15 @@ export default function Layout(props: ParentProps) {
960960
void openProject(target.worktree)
961961
}
962962

963+
function navigateToProjectIndex(index: number) {
964+
const projects = layout.projects.list()
965+
const target = projects[index]
966+
if (!target) return
967+
968+
globalSync.child(target.worktree)
969+
void openProject(target.worktree)
970+
}
971+
963972
function navigateSessionByUnseen(offset: number) {
964973
const sessions = currentSessions()
965974
if (sessions.length === 0) return
@@ -1040,6 +1049,19 @@ export default function Layout(props: ParentProps) {
10401049
keybind: "mod+alt+arrowdown",
10411050
onSelect: () => navigateProjectByOffset(1),
10421051
},
1052+
...Array.from({ length: 9 }, (_, i) => {
1053+
const index = i
1054+
const number = index + 1
1055+
return {
1056+
id: `project.${number}`,
1057+
category: language.t("command.category.project"),
1058+
title: `Open Project {number}`,
1059+
keybind: `mod+${number}`,
1060+
disabled: layout.projects.list().length <= index,
1061+
hidden: true,
1062+
onSelect: () => navigateToProjectIndex(index),
1063+
}
1064+
}),
10431065
{
10441066
id: "provider.connect",
10451067
title: language.t("command.provider.connect"),

0 commit comments

Comments
 (0)