diff options
| author | Nalin Singh <[email protected]> | 2025-12-18 02:05:46 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-17 14:35:46 -0600 |
| commit | a8c499ae8feb459a5e5411ee6346399a2895e9a3 (patch) | |
| tree | b684619372e746203b827940e1d04247abd839ec | |
| parent | 24430287c5a304ee35ad0089bad1907d7917dee2 (diff) | |
| download | opencode-a8c499ae8feb459a5e5411ee6346399a2895e9a3.tar.gz opencode-a8c499ae8feb459a5e5411ee6346399a2895e9a3.zip | |
fix: prevent session list selection from jumping to active session when confirming delete (#5666)
| -rw-r--r-- | packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx | 46 |
1 files changed, 26 insertions, 20 deletions
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 8e9c17f70..ff9745b90 100644 --- a/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx +++ b/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx @@ -1,7 +1,7 @@ import { InputRenderable, RGBA, ScrollBoxRenderable, TextAttributes } from "@opentui/core" import { useTheme, selectedForeground } from "@tui/context/theme" import { entries, filter, flatMap, groupBy, pipe, take } from "remeda" -import { batch, createEffect, createMemo, For, Show, type JSX } from "solid-js" +import { batch, createEffect, createMemo, For, Show, type JSX, on } from "solid-js" import { createStore } from "solid-js/store" import { useKeyboard, useTerminalDimensions } from "@opentui/solid" import * as fuzzysort from "fuzzysort" @@ -53,14 +53,19 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) { filter: "", }) - createEffect(() => { - if (props.current) { - const currentIndex = flat().findIndex((opt) => isDeepEqual(opt.value, props.current)) - if (currentIndex >= 0) { - setStore("selected", currentIndex) - } - } - }) + createEffect( + on( + () => props.current, + (current) => { + if (current) { + const currentIndex = flat().findIndex((opt) => isDeepEqual(opt.value, current)) + if (currentIndex >= 0) { + setStore("selected", currentIndex) + } + } + }, + ), + ) let input: InputRenderable @@ -98,18 +103,19 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) { const selected = createMemo(() => flat()[store.selected]) - createEffect(() => { - store.filter - if (store.filter.length > 0) { - setStore("selected", 0) - } else if (props.current) { - const currentIndex = flat().findIndex((opt) => isDeepEqual(opt.value, props.current)) - if (currentIndex >= 0) { - setStore("selected", currentIndex) + createEffect( + on([() => store.filter, () => props.current], ([filter, current]) => { + if (filter.length > 0) { + setStore("selected", 0) + } else if (current) { + const currentIndex = flat().findIndex((opt) => isDeepEqual(opt.value, current)) + if (currentIndex >= 0) { + setStore("selected", currentIndex) + } } - } - scroll.scrollTo(0) - }) + scroll.scrollTo(0) + }), + ) function move(direction: number) { let next = store.selected + direction |
