mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-13 23:52:06 +00:00
feat(app): add ctrl/cmd+number keybinds to switch projects (#26280)
This commit is contained in:
@@ -107,7 +107,7 @@ function createCommandEntries(props: {
|
|||||||
const allowed = createMemo(() => {
|
const allowed = createMemo(() => {
|
||||||
if (props.filesOnly()) return []
|
if (props.filesOnly()) return []
|
||||||
return props.command.options.filter(
|
return props.command.options.filter(
|
||||||
(option) => !option.disabled && !option.id.startsWith("suggested.") && option.id !== "file.open",
|
(option) => !option.disabled && !option.hidden && !option.id.startsWith("suggested.") && option.id !== "file.open",
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -123,11 +123,13 @@ function listFor(command: CommandContext, map: KeybindMap, palette: string) {
|
|||||||
|
|
||||||
for (const opt of command.catalog) {
|
for (const opt of command.catalog) {
|
||||||
if (opt.id.startsWith("suggested.")) continue
|
if (opt.id.startsWith("suggested.")) continue
|
||||||
|
if (opt.hidden) continue
|
||||||
out.set(opt.id, { title: opt.title, group: groupFor(opt.id) })
|
out.set(opt.id, { title: opt.title, group: groupFor(opt.id) })
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const opt of command.options) {
|
for (const opt of command.options) {
|
||||||
if (opt.id.startsWith("suggested.")) continue
|
if (opt.id.startsWith("suggested.")) continue
|
||||||
|
if (opt.hidden) continue
|
||||||
out.set(opt.id, { title: opt.title, group: groupFor(opt.id) })
|
out.set(opt.id, { title: opt.title, group: groupFor(opt.id) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ export interface CommandOption {
|
|||||||
slash?: string
|
slash?: string
|
||||||
suggested?: boolean
|
suggested?: boolean
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
|
hidden?: boolean
|
||||||
onSelect?: (source?: "palette" | "keybind" | "slash") => void
|
onSelect?: (source?: "palette" | "keybind" | "slash") => void
|
||||||
onHighlight?: () => (() => void) | void
|
onHighlight?: () => (() => void) | void
|
||||||
}
|
}
|
||||||
@@ -93,6 +94,7 @@ export type CommandCatalogItem = {
|
|||||||
category?: string
|
category?: string
|
||||||
keybind?: KeybindConfig
|
keybind?: KeybindConfig
|
||||||
slash?: string
|
slash?: string
|
||||||
|
hidden?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CommandRegistration = {
|
export type CommandRegistration = {
|
||||||
@@ -279,13 +281,14 @@ export const { use: useCommand, provider: CommandProvider } = createSimpleContex
|
|||||||
setCatalog(
|
setCatalog(
|
||||||
registered().reduce((acc, opt) => {
|
registered().reduce((acc, opt) => {
|
||||||
const id = actionId(opt.id)
|
const id = actionId(opt.id)
|
||||||
acc[id] = {
|
if (opt.title)
|
||||||
title: opt.title,
|
acc[id] = {
|
||||||
description: opt.description,
|
title: opt.title,
|
||||||
category: opt.category,
|
description: opt.description,
|
||||||
keybind: opt.keybind,
|
category: opt.category,
|
||||||
slash: opt.slash,
|
keybind: opt.keybind,
|
||||||
}
|
slash: opt.slash,
|
||||||
|
}
|
||||||
return acc
|
return acc
|
||||||
}, {} as CommandCatalog),
|
}, {} as CommandCatalog),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export const dict = {
|
|||||||
"command.project.open": "Open project",
|
"command.project.open": "Open project",
|
||||||
"command.project.previous": "Previous project",
|
"command.project.previous": "Previous project",
|
||||||
"command.project.next": "Next project",
|
"command.project.next": "Next project",
|
||||||
|
"command.project.index": "Switch to project {{index}}",
|
||||||
"command.provider.connect": "Connect provider",
|
"command.provider.connect": "Connect provider",
|
||||||
"command.server.switch": "Switch server",
|
"command.server.switch": "Switch server",
|
||||||
"command.settings.open": "Open settings",
|
"command.settings.open": "Open settings",
|
||||||
|
|||||||
@@ -960,6 +960,15 @@ export default function Layout(props: ParentProps) {
|
|||||||
void openProject(target.worktree)
|
void openProject(target.worktree)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function navigateToProjectIndex(index: number) {
|
||||||
|
const projects = layout.projects.list()
|
||||||
|
const target = projects[index]
|
||||||
|
if (!target) return
|
||||||
|
|
||||||
|
globalSync.child(target.worktree)
|
||||||
|
void openProject(target.worktree)
|
||||||
|
}
|
||||||
|
|
||||||
function navigateSessionByUnseen(offset: number) {
|
function navigateSessionByUnseen(offset: number) {
|
||||||
const sessions = currentSessions()
|
const sessions = currentSessions()
|
||||||
if (sessions.length === 0) return
|
if (sessions.length === 0) return
|
||||||
@@ -1040,6 +1049,19 @@ export default function Layout(props: ParentProps) {
|
|||||||
keybind: "mod+alt+arrowdown",
|
keybind: "mod+alt+arrowdown",
|
||||||
onSelect: () => navigateProjectByOffset(1),
|
onSelect: () => navigateProjectByOffset(1),
|
||||||
},
|
},
|
||||||
|
...Array.from({ length: 9 }, (_, i) => {
|
||||||
|
const index = i
|
||||||
|
const number = index + 1
|
||||||
|
return {
|
||||||
|
id: `project.${number}`,
|
||||||
|
category: language.t("command.category.project"),
|
||||||
|
title: `Open Project {number}`,
|
||||||
|
keybind: `mod+${number}`,
|
||||||
|
disabled: layout.projects.list().length <= index,
|
||||||
|
hidden: true,
|
||||||
|
onSelect: () => navigateToProjectIndex(index),
|
||||||
|
}
|
||||||
|
}),
|
||||||
{
|
{
|
||||||
id: "provider.connect",
|
id: "provider.connect",
|
||||||
title: language.t("command.provider.connect"),
|
title: language.t("command.provider.connect"),
|
||||||
|
|||||||
Reference in New Issue
Block a user