Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 9e49870

Browse files
committed
remember sidebar position
1 parent fe38e3a commit 9e49870

6 files changed

Lines changed: 39 additions & 32 deletions

File tree

packages/opencode/src/cli/cmd/tui/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ function App() {
249249

250250
createEffect(() => {
251251
const providerID = local.model.current().providerID
252-
if (providerID === "openrouter" && !kv.data.openrouter_warning) {
252+
if (providerID === "openrouter" && !kv.get("openrouter_warning", false)) {
253253
untrack(() => {
254254
DialogAlert.show(
255255
dialog,

packages/opencode/src/cli/cmd/tui/component/dialog-session-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export function DialogSessionList() {
7676
},
7777
},
7878
{
79-
keybind: Keybind.parse("r")[0],
79+
keybind: Keybind.parse("ctrl+r")[0],
8080
title: "rename",
8181
onTrigger: async (option) => {
8282
dialog.replace(() => <DialogSessionRename session={option.value} />)
Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Global } from "@/global"
2-
import { createSignal } from "solid-js"
2+
import { createSignal, type Setter } from "solid-js"
33
import { createStore } from "solid-js/store"
44
import { createSimpleContext } from "./helper"
55
import path from "path"
@@ -8,10 +8,7 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({
88
name: "KV",
99
init: () => {
1010
const [ready, setReady] = createSignal(false)
11-
const [kvStore, setKvStore] = createStore({
12-
openrouter_warning: false,
13-
theme: "opencode",
14-
})
11+
const [kvStore, setKvStore] = createStore<Record<string, any>>()
1512
const file = Bun.file(path.join(Global.Path.state, "kv.json"))
1613

1714
file
@@ -24,22 +21,29 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({
2421
setReady(true)
2522
})
2623

27-
return {
28-
get data() {
29-
return kvStore
30-
},
24+
const result = {
3125
get ready() {
3226
return ready()
3327
},
28+
signal<T>(name: string, defaultValue: T) {
29+
if (!kvStore[name]) setKvStore(name, defaultValue)
30+
return [
31+
function () {
32+
return result.get(name)
33+
},
34+
function setter(next: Setter<T>) {
35+
result.set(name, next)
36+
},
37+
] as const
38+
},
39+
get(key: string, defaultValue?: any) {
40+
return kvStore[key] ?? defaultValue
41+
},
3442
set(key: string, value: any) {
35-
setKvStore(key as any, value)
36-
Bun.write(
37-
file,
38-
JSON.stringify({
39-
[key]: value,
40-
}),
41-
)
43+
setKvStore(key, value)
44+
Bun.write(file, JSON.stringify(kvStore, null, 2))
4245
},
4346
}
47+
return result
4448
},
4549
})

packages/opencode/src/cli/cmd/tui/context/theme.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
629629
const sync = useSync()
630630
const kv = useKV()
631631

632-
const [theme, setTheme] = createSignal(sync.data.config.theme ?? kv.data.theme)
632+
const [theme, setTheme] = createSignal(sync.data.config.theme ?? kv.get("theme", "opencode"))
633633

634634
const values = createMemo(() => {
635635
return THEMES[theme()] ?? THEMES.opencode
@@ -643,7 +643,7 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
643643
},
644644
}),
645645
get selected() {
646-
return kv.data.theme
646+
return theme()
647647
},
648648
set(theme: string) {
649649
if (!THEMES[theme]) return

packages/opencode/src/cli/cmd/tui/routes/session/index.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import parsers from "../../../../../../parsers-config.ts"
6565
import { Clipboard } from "../../util/clipboard"
6666
import { Toast, useToast } from "../../ui/toast"
6767
import { DialogSessionRename } from "../../component/dialog-session-rename"
68+
import { useKV } from "../../context/kv.tsx"
6869

6970
addDefaultParsers(parsers.parsers)
7071

@@ -82,6 +83,7 @@ function use() {
8283
export function Session() {
8384
const route = useRouteData("session")
8485
const sync = useSync()
86+
const kv = useKV()
8587
const { theme } = useTheme()
8688
const session = createMemo(() => sync.session.get(route.sessionID)!)
8789
const messages = createMemo(() => sync.data.message[route.sessionID] ?? [])
@@ -92,7 +94,7 @@ export function Session() {
9294
})
9395

9496
const dimensions = useTerminalDimensions()
95-
const [sidebar, setSidebar] = createSignal<"show" | "hide" | "auto">("auto")
97+
const [sidebar, setSidebar] = createSignal<"show" | "hide" | "auto">(kv.get("sidebar", "auto"))
9698
const [conceal, setConceal] = createSignal(true)
9799

98100
const wide = createMemo(() => dimensions().width > 120)
@@ -200,19 +202,18 @@ export function Session() {
200202
disabled: !!session()?.share?.url,
201203
category: "Session",
202204
onSelect: async (dialog) => {
203-
await sdk.client.session.share({
204-
path: {
205-
id: route.sessionID,
206-
},
207-
})
205+
await sdk.client.session
206+
.share({
207+
path: {
208+
id: route.sessionID,
209+
},
210+
})
208211
.then((res) =>
209212
Clipboard.copy(res.data!.share!.url).catch(() =>
210-
toast.show({ message: "Failed to copy URL to clipboard", variant: "error" })
211-
)
212-
)
213-
.then(() =>
214-
toast.show({ message: "Share URL copied to clipboard!", variant: "success" })
213+
toast.show({ message: "Failed to copy URL to clipboard", variant: "error" }),
214+
),
215215
)
216+
.then(() => toast.show({ message: "Share URL copied to clipboard!", variant: "success" }))
216217
.catch(() => toast.show({ message: "Failed to share session", variant: "error" }))
217218
dialog.clear()
218219
},
@@ -306,6 +307,8 @@ export function Session() {
306307
if (prev === "show") return "hide"
307308
return "show"
308309
})
310+
if (sidebar() === "show") kv.set("sidebar", "auto")
311+
if (sidebar() === "hide") kv.set("sidebar", "hide")
309312
dialog.clear()
310313
},
311314
},

packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
242242
)}
243243
</For>
244244
</scrollbox>
245-
<box paddingRight={2} paddingLeft={3} flexDirection="row" paddingBottom={1}>
245+
<box paddingRight={2} paddingLeft={3} flexDirection="row" paddingBottom={1} gap={1}>
246246
<For each={props.keybind ?? []}>
247247
{(item) => (
248248
<text>

0 commit comments

Comments
 (0)