Skip to content

Commit 161f966

Browse files
BrendonovichBenGu3
authored andcommitted
fix(app): enable composer shortcuts on drafts (anomalyco#33956)
1 parent 0c963ac commit 161f966

4 files changed

Lines changed: 74 additions & 49 deletions

File tree

packages/app/src/pages/new-session.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
SessionComposerRegion,
1414
} from "@/pages/session/composer"
1515
import { useSessionKey } from "@/pages/session/session-layout"
16+
import { useComposerCommands } from "@/pages/session/use-composer-commands"
1617

1718
/**
1819
* The `/new-session` draft page. Unlike `session.tsx`, this only renders the prompt
@@ -28,6 +29,8 @@ export default function NewSessionPage() {
2829
const route = useSessionKey()
2930
const [searchParams, setSearchParams] = useSearchParams<{ draftId?: string; prompt?: string }>()
3031

32+
useComposerCommands()
33+
3134
let inputRef: HTMLDivElement | undefined
3235

3336
const composer = createSessionComposerState()

packages/app/src/pages/session.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import { useSessionLayout } from "@/pages/session/session-layout"
6363
import { syncSessionModel } from "@/pages/session/session-model-helpers"
6464
import { SessionSidePanel } from "@/pages/session/session-side-panel"
6565
import { TerminalPanel } from "@/pages/session/terminal-panel"
66+
import { useComposerCommands } from "@/pages/session/use-composer-commands"
6667
import { useSessionCommands } from "@/pages/session/use-session-commands"
6768
import { useSessionHashScroll } from "@/pages/session/use-session-hash-scroll"
6869
import { Identifier } from "@/utils/id"
@@ -783,6 +784,7 @@ export default function Page() {
783784
inputRef?.focus()
784785
}
785786

787+
useComposerCommands()
786788
useSessionCommands({
787789
navigateMessageByOffset,
788790
setActiveMessage,
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { useCommand, type CommandOption } from "@/context/command"
2+
import { useLanguage } from "@/context/language"
3+
import { useLocal } from "@/context/local"
4+
import { useSettings } from "@/context/settings"
5+
import { useDialog } from "@opencode-ai/ui/context/dialog"
6+
import { useSessionLayout } from "./session-layout"
7+
import { createSessionOwnership } from "./session-ownership"
8+
9+
const withCategory = (category: string) => {
10+
return (option: Omit<CommandOption, "category">): CommandOption => ({
11+
...option,
12+
category,
13+
})
14+
}
15+
16+
export const useComposerCommands = () => {
17+
const command = useCommand()
18+
const dialog = useDialog()
19+
const language = useLanguage()
20+
const local = useLocal()
21+
const settings = useSettings()
22+
const { sessionKey } = useSessionLayout()
23+
const sessionOwnership = createSessionOwnership(sessionKey)
24+
const modelCommand = withCategory(language.t("command.category.model"))
25+
const agentCommand = withCategory(language.t("command.category.agent"))
26+
27+
const chooseModel = async () => {
28+
const owner = sessionOwnership.capture()
29+
const { DialogSelectModel } = await import("@/components/dialog-select-model")
30+
owner.run(() => {
31+
void dialog.show(() => <DialogSelectModel model={local.model} />)
32+
})
33+
}
34+
35+
command.register("composer", () => [
36+
modelCommand({
37+
id: "model.choose",
38+
title: language.t("command.model.choose"),
39+
description: language.t("command.model.choose.description"),
40+
keybind: "mod+'",
41+
slash: "model",
42+
onSelect: chooseModel,
43+
}),
44+
modelCommand({
45+
id: "model.variant.cycle",
46+
title: language.t("command.model.variant.cycle"),
47+
description: language.t("command.model.variant.cycle.description"),
48+
keybind: "shift+mod+d",
49+
onSelect: () => local.model.variant.cycle(),
50+
}),
51+
agentCommand({
52+
id: "agent.cycle",
53+
title: language.t("command.agent.cycle"),
54+
description: language.t("command.agent.cycle.description"),
55+
keybind: "mod+.",
56+
slash: "agent",
57+
disabled: !settings.visibility.customAgents(),
58+
onSelect: () => local.agent.move(1),
59+
}),
60+
agentCommand({
61+
id: "agent.cycle.reverse",
62+
title: language.t("command.agent.cycle.reverse"),
63+
description: language.t("command.agent.cycle.reverse.description"),
64+
keybind: "shift+mod+.",
65+
disabled: !settings.visibility.customAgents(),
66+
onSelect: () => local.agent.move(-1),
67+
}),
68+
])
69+
}

packages/app/src/pages/session/use-session-commands.tsx

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ export const useSessionCommands = (actions: SessionCommandContext) => {
136136
const contextCommand = withCategory(language.t("command.category.context"))
137137
const viewCommand = withCategory(language.t("command.category.view"))
138138
const terminalCommand = withCategory(language.t("command.category.terminal"))
139-
const modelCommand = withCategory(language.t("command.category.model"))
140139
const mcpCommand = withCategory(language.t("command.category.mcp"))
141-
const agentCommand = withCategory(language.t("command.category.agent"))
142140
const permissionsCommand = withCategory(language.t("command.category.permissions"))
143141

144142
const isAutoAcceptActive = () => {
@@ -271,13 +269,6 @@ export const useSessionCommands = (actions: SessionCommandContext) => {
271269
view().terminal.open()
272270
}
273271

274-
const chooseModel = () => {
275-
void openDialog(
276-
() => import("@/components/dialog-select-model"),
277-
(x) => dialog.show(() => <x.DialogSelectModel model={local.model} />),
278-
)
279-
}
280-
281272
const chooseMcp = () => {
282273
void openDialog(
283274
() => import("@/components/dialog-select-mcp"),
@@ -555,24 +546,6 @@ export const useSessionCommands = (actions: SessionCommandContext) => {
555546
}),
556547
]
557548

558-
const modelCmds = () => [
559-
modelCommand({
560-
id: "model.choose",
561-
title: language.t("command.model.choose"),
562-
description: language.t("command.model.choose.description"),
563-
keybind: "mod+'",
564-
slash: "model",
565-
onSelect: chooseModel,
566-
}),
567-
modelCommand({
568-
id: "model.variant.cycle",
569-
title: language.t("command.model.variant.cycle"),
570-
description: language.t("command.model.variant.cycle.description"),
571-
keybind: "shift+mod+d",
572-
onSelect: () => local.model.variant.cycle(),
573-
}),
574-
]
575-
576549
const mcpCmds = () => [
577550
mcpCommand({
578551
id: "mcp.toggle",
@@ -584,26 +557,6 @@ export const useSessionCommands = (actions: SessionCommandContext) => {
584557
}),
585558
]
586559

587-
const agentCmds = () => [
588-
agentCommand({
589-
id: "agent.cycle",
590-
title: language.t("command.agent.cycle"),
591-
description: language.t("command.agent.cycle.description"),
592-
keybind: "mod+.",
593-
slash: "agent",
594-
disabled: !settings.visibility.customAgents(),
595-
onSelect: () => local.agent.move(1),
596-
}),
597-
agentCommand({
598-
id: "agent.cycle.reverse",
599-
title: language.t("command.agent.cycle.reverse"),
600-
description: language.t("command.agent.cycle.reverse.description"),
601-
keybind: "shift+mod+.",
602-
disabled: !settings.visibility.customAgents(),
603-
onSelect: () => local.agent.move(-1),
604-
}),
605-
]
606-
607560
const permissionsCmds = () => [
608561
permissionsCommand({
609562
id: "permissions.autoaccept",
@@ -624,9 +577,7 @@ export const useSessionCommands = (actions: SessionCommandContext) => {
624577
...viewCmds(),
625578
...terminalCmds(),
626579
...messageCmds(),
627-
...modelCmds(),
628580
...mcpCmds(),
629-
...agentCmds(),
630581
...permissionsCmds(),
631582
])
632583
}

0 commit comments

Comments
 (0)