tui: prevent crash when opening session switcher from an active session

This commit is contained in:
Dax Raad 2026-07-13 21:04:36 -04:00
commit 5cf24bf185
2 changed files with 21 additions and 3 deletions

View file

@ -155,11 +155,10 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
.filter((item) => item.label), .filter((item) => item.label),
...(props.footerHints ?? []), ...(props.footerHints ?? []),
]) ])
const actionItems = createMemo(() => const actionItems = () =>
visibleActions() visibleActions()
.filter(isActionItem) .filter(isActionItem)
.filter((item) => !isActionDisabled(item)), .filter((item) => !isActionDisabled(item))
)
createEffect(() => { createEffect(() => {
const index = focusedAction() const index = focusedAction()

View file

@ -16,6 +16,7 @@ async function renderSelect(
options: DialogSelectOption<string>[], options: DialogSelectOption<string>[],
onGlobal: () => void, onGlobal: () => void,
onRow: (option: DialogSelectOption<string>) => void, onRow: (option: DialogSelectOption<string>) => void,
current?: string,
) { ) {
const state = path.join(root, "state") const state = path.join(root, "state")
await mkdir(state, { recursive: true }) await mkdir(state, { recursive: true })
@ -52,6 +53,7 @@ async function renderSelect(
<DialogSelect <DialogSelect
title="Items" title="Items"
options={options} options={options}
current={current}
actions={[ actions={[
{ {
command: "dialog.move_session.delete", command: "dialog.move_session.delete",
@ -153,6 +155,23 @@ async function mountSelect(root: string, initial: DialogSelectOption<string>[])
return { app, moved, replaceOptions, selected } return { app, moved, replaceOptions, selected }
} }
test("renders actions with a current selection", async () => {
await using tmp = await tmpdir()
const app = await renderSelect(
tmp.path,
[{ title: "Alpha", value: "alpha" }],
() => {},
() => {},
"alpha",
)
try {
await app.waitForFrame((frame) => frame.includes("delete"))
} finally {
app.renderer.destroy()
}
})
test("dialog actions run without options while row actions still require a selection", async () => { test("dialog actions run without options while row actions still require a selection", async () => {
await using tmp = await tmpdir() await using tmp = await tmpdir()
let global = 0 let global = 0