Ver Fonte

fix: prevent session list selection from jumping to active session when confirming delete (#5666)

Nalin Singh há 2 meses atrás
pai
commit
a8c499ae8f
1 ficheiros alterados com 26 adições e 20 exclusões
  1. 26 20
      packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx

+ 26 - 20
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