Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useDialog } from "@tui/ui/dialog"
import { DialogSelect } from "@tui/ui/dialog-select"
import { DialogSelect, type DialogSelectRef } from "@tui/ui/dialog-select"
import { useRoute } from "@tui/context/route"
import { useSync } from "@tui/context/sync"
import { createMemo, createSignal, createResource, onMount, Show } from "solid-js"
Expand All @@ -23,6 +23,8 @@ export function DialogSessionList() {

const [toDelete, setToDelete] = createSignal<string>()
const [search, setSearch] = createDebouncedSignal("", 150)
const [selectRef, setSelectRef] = createSignal<DialogSelectRef<string>>()


const [searchResults] = createResource(search, async (query) => {
if (!query) return undefined
Expand Down Expand Up @@ -65,6 +67,7 @@ export function DialogSessionList() {

return (
<DialogSelect
ref={setSelectRef}
title="Sessions"
options={options()}
skipFilter={true}
Expand All @@ -86,10 +89,26 @@ export function DialogSessionList() {
title: "delete",
onTrigger: async (option) => {
if (toDelete() === option.value) {
// Find current index before deletion
const ref = selectRef()
const currentIndex = ref?.filtered.findIndex((opt) => opt.value === option.value) ?? -1

sdk.client.session.delete({
sessionID: option.value,
})
setToDelete(undefined)

// Move to adjacent item after deletion
if (ref && currentIndex >= 0) {
setTimeout(() => {
// Try to stay at same index (which will be next item after deletion)
// Or go to previous if we were at the end
const newIndex = Math.min(currentIndex, ref.filtered.length - 1)
if (newIndex >= 0) {
ref.moveTo(newIndex, true)
}
}, 50)
}
return
}
setToDelete(option.value)
Expand Down
2 changes: 2 additions & 0 deletions packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface DialogSelectOption<T = any> {
export type DialogSelectRef<T> = {
filter: string
filtered: DialogSelectOption<T>[]
moveTo: (index: number, center?: boolean) => void
}

export function DialogSelect<T>(props: DialogSelectProps<T>) {
Expand Down Expand Up @@ -224,6 +225,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
get filtered() {
return filtered()
},
moveTo,
}
props.ref?.(ref)

Expand Down