From 28f10bb1473fcad77b665461b73209a12dd03994 Mon Sep 17 00:00:00 2001 From: Ariane Emory Date: Sun, 17 May 2026 14:28:42 -0400 Subject: [PATCH] fix(dialog-select): preserve selection when options reorder When options are reordered (e.g., favorite/unfavorite in model list), the highlighted selection was staying at the same row index and pointing to a different item. Now we use on(() => flat(), ...) with the previous flat array to find the previously selected value in the new options list and restore the selection to the correct index. --- .../src/cli/cmd/tui/ui/dialog-select.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx b/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx index a791aebc307a..36a2bb31957c 100644 --- a/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx +++ b/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx @@ -185,6 +185,23 @@ export function DialogSelect(props: DialogSelectProps) { }), ) + // Preserve highlighted selection when options reorder (e.g., favorite/unfavorite) + createEffect( + on( + () => flat(), + (newFlat, prevFlat) => { + if (store.filter.length > 0) return + if (!prevFlat) return + const prevSelected = prevFlat[store.selected] + if (!prevSelected) return + const newIndex = newFlat.findIndex((opt) => isDeepEqual(opt.value, prevSelected.value)) + if (newIndex >= 0 && newIndex !== store.selected) { + moveTo(newIndex, false) + } + }, + ), + ) + function move(direction: number) { if (flat().length === 0) return let next = store.selected + direction