Skip to content

Commit 81673f9

Browse files
Apply PR #14814: Change keybindings to navigate between child sessions
2 parents 9a3583e + a48b3d1 commit 81673f9

File tree

2 files changed

+62
-29
lines changed

2 files changed

+62
-29
lines changed

packages/opencode/src/cli/cmd/tui/routes/session/index.tsx

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import type { SkillTool } from "@/tool/skill"
4848
import { useKeyboard, useRenderer, useTerminalDimensions, type JSX } from "@opentui/solid"
4949
import { useSDK } from "@tui/context/sdk"
5050
import { useCommandDialog } from "@tui/component/dialog-command"
51+
import type { DialogContext } from "@tui/ui/dialog"
5152
import { useKeybind } from "@tui/context/keybind"
5253
import { Header } from "./header"
5354
import { parsePatch } from "diff"
@@ -226,6 +227,8 @@ export function Session() {
226227
let scroll: ScrollBoxRenderable
227228
let prompt: PromptRef
228229
const keybind = useKeybind()
230+
const dialog = useDialog()
231+
const renderer = useRenderer()
229232

230233
// Allow exit when in child session (prompt is hidden)
231234
const exit = useExit()
@@ -312,19 +315,40 @@ export function Session() {
312315

313316
const local = useLocal()
314317

318+
function moveFirstChild() {
319+
if (children().length === 1) return
320+
const next = children().find((x) => !!x.parentID)
321+
if (next) {
322+
navigate({
323+
type: "session",
324+
sessionID: next.id,
325+
})
326+
}
327+
}
328+
315329
function moveChild(direction: number) {
316330
if (children().length === 1) return
317-
let next = children().findIndex((x) => x.id === session()?.id) + direction
318-
if (next >= children().length) next = 0
319-
if (next < 0) next = children().length - 1
320-
if (children()[next]) {
331+
332+
const sessions = children().filter((x) => !!x.parentID)
333+
let next = sessions.findIndex((x) => x.id === session()?.id) + direction
334+
335+
if (next >= sessions.length) next = 0
336+
if (next < 0) next = sessions.length - 1
337+
if (sessions[next]) {
321338
navigate({
322339
type: "session",
323-
sessionID: children()[next].id,
340+
sessionID: sessions[next].id,
324341
})
325342
}
326343
}
327344

345+
function childSessionHandler(func: (dialog: DialogContext) => void) {
346+
return (dialog: DialogContext) => {
347+
if (!session()?.parentID || dialog.stack.length > 0) return
348+
func(dialog)
349+
}
350+
}
351+
328352
const command = useCommandDialog()
329353
command.register(() => [
330354
{
@@ -890,24 +914,13 @@ export function Session() {
890914
},
891915
},
892916
{
893-
title: "Next child session",
894-
value: "session.child.next",
895-
keybind: "session_child_cycle",
896-
category: "Session",
897-
hidden: true,
898-
onSelect: (dialog) => {
899-
moveChild(1)
900-
dialog.clear()
901-
},
902-
},
903-
{
904-
title: "Previous child session",
905-
value: "session.child.previous",
906-
keybind: "session_child_cycle_reverse",
917+
title: "Go to child session",
918+
value: "session.child.first",
919+
keybind: "session_child_first",
907920
category: "Session",
908921
hidden: true,
909922
onSelect: (dialog) => {
910-
moveChild(-1)
923+
moveFirstChild()
911924
dialog.clear()
912925
},
913926
},
@@ -917,7 +930,7 @@ export function Session() {
917930
keybind: "session_parent",
918931
category: "Session",
919932
hidden: true,
920-
onSelect: (dialog) => {
933+
onSelect: childSessionHandler((dialog) => {
921934
const parentID = session()?.parentID
922935
if (parentID) {
923936
navigate({
@@ -926,7 +939,29 @@ export function Session() {
926939
})
927940
}
928941
dialog.clear()
929-
},
942+
}),
943+
},
944+
{
945+
title: "Next child session",
946+
value: "session.child.next",
947+
keybind: "session_child_cycle",
948+
category: "Session",
949+
hidden: true,
950+
onSelect: childSessionHandler((dialog) => {
951+
moveChild(1)
952+
dialog.clear()
953+
}),
954+
},
955+
{
956+
title: "Previous child session",
957+
value: "session.child.previous",
958+
keybind: "session_child_cycle_reverse",
959+
category: "Session",
960+
hidden: true,
961+
onSelect: childSessionHandler((dialog) => {
962+
moveChild(-1)
963+
dialog.clear()
964+
}),
930965
},
931966
])
932967

@@ -977,9 +1012,6 @@ export function Session() {
9771012
}
9781013
})
9791014

980-
const dialog = useDialog()
981-
const renderer = useRenderer()
982-
9831015
// snap to bottom when session changes
9841016
createEffect(on(() => route.sessionID, toBottom))
9851017

@@ -1939,7 +1971,7 @@ function Task(props: ToolProps<typeof TaskTool>) {
19391971
</box>
19401972
<Show when={props.metadata.sessionId}>
19411973
<text fg={theme.text}>
1942-
{keybind.print("session_child_cycle")}
1974+
{keybind.print("session_child_first")}
19431975
<span style={{ fg: theme.textMuted }}> view subagents</span>
19441976
</text>
19451977
</Show>

packages/opencode/src/config/config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,10 @@ export namespace Config {
902902
.describe("Delete word backward in input"),
903903
history_previous: z.string().optional().default("up").describe("Previous history item"),
904904
history_next: z.string().optional().default("down").describe("Next history item"),
905-
session_child_cycle: z.string().optional().default("<leader>right").describe("Next child session"),
906-
session_child_cycle_reverse: z.string().optional().default("<leader>left").describe("Previous child session"),
907-
session_parent: z.string().optional().default("<leader>up").describe("Go to parent session"),
905+
session_child_first: z.string().optional().default("<leader>down").describe("Go to first child session"),
906+
session_child_cycle: z.string().optional().default("right").describe("Go to next child session"),
907+
session_child_cycle_reverse: z.string().optional().default("left").describe("Go to previous child session"),
908+
session_parent: z.string().optional().default("up").describe("Go to parent session"),
908909
terminal_suspend: z.string().optional().default("ctrl+z").describe("Suspend terminal"),
909910
terminal_title_toggle: z.string().optional().default("none").describe("Toggle terminal title"),
910911
tips_toggle: z.string().optional().default("<leader>h").describe("Toggle tips on home screen"),

0 commit comments

Comments
 (0)