summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/context
diff options
context:
space:
mode:
authorHalil Tezcan KARABULUT <[email protected]>2026-01-21 15:49:46 +0300
committerGitHub <[email protected]>2026-01-21 06:49:46 -0600
commit87d91c29e23d136436342542f83a20bfc4a3d0bf (patch)
tree390b43083bec0c662d1df2d490a7b46bc9102680 /packages/app/src/context
parent259b2a3c2dbb785dd46c83e243f20436a05e3021 (diff)
downloadopencode-87d91c29e23d136436342542f83a20bfc4a3d0bf.tar.gz
opencode-87d91c29e23d136436342542f83a20bfc4a3d0bf.zip
fix(app): terminal improvements - focus, rename, error state, CSP (#9700)
Diffstat (limited to 'packages/app/src/context')
-rw-r--r--packages/app/src/context/terminal.tsx48
1 files changed, 33 insertions, 15 deletions
diff --git a/packages/app/src/context/terminal.tsx b/packages/app/src/context/terminal.tsx
index 8bde12da1..147c4f8f7 100644
--- a/packages/app/src/context/terminal.tsx
+++ b/packages/app/src/context/terminal.tsx
@@ -13,6 +13,7 @@ export type LocalPTY = {
cols?: number
buffer?: string
scrollY?: number
+ error?: boolean
}
const WORKSPACE_KEY = "__workspace__"
@@ -107,14 +108,15 @@ function createTerminalSession(sdk: ReturnType<typeof useSDK>, dir: string, sess
.then((pty) => {
const id = pty.data?.id
if (!id) return
- setStore("all", [
- ...store.all,
- {
- id,
- title: pty.data?.title ?? "Terminal",
- titleNumber: nextNumber,
- },
- ])
+ const newTerminal = {
+ id,
+ title: pty.data?.title ?? "Terminal",
+ titleNumber: nextNumber,
+ }
+ setStore("all", (all) => {
+ const newAll = [...all, newTerminal]
+ return newAll
+ })
setStore("active", id)
})
.catch((e) => {
@@ -122,7 +124,10 @@ function createTerminalSession(sdk: ReturnType<typeof useSDK>, dir: string, sess
})
},
update(pty: Partial<LocalPTY> & { id: string }) {
- setStore("all", (x) => x.map((x) => (x.id === pty.id ? { ...x, ...pty } : x)))
+ const index = store.all.findIndex((x) => x.id === pty.id)
+ if (index !== -1) {
+ setStore("all", index, (existing) => ({ ...existing, ...pty }))
+ }
sdk.client.pty
.update({
ptyID: pty.id,
@@ -157,18 +162,29 @@ function createTerminalSession(sdk: ReturnType<typeof useSDK>, dir: string, sess
open(id: string) {
setStore("active", id)
},
+ next() {
+ const index = store.all.findIndex((x) => x.id === store.active)
+ if (index === -1) return
+ const nextIndex = (index + 1) % store.all.length
+ setStore("active", store.all[nextIndex]?.id)
+ },
+ previous() {
+ const index = store.all.findIndex((x) => x.id === store.active)
+ if (index === -1) return
+ const prevIndex = index === 0 ? store.all.length - 1 : index - 1
+ setStore("active", store.all[prevIndex]?.id)
+ },
async close(id: string) {
batch(() => {
- setStore(
- "all",
- store.all.filter((x) => x.id !== id),
- )
+ const filtered = store.all.filter((x) => x.id !== id)
if (store.active === id) {
const index = store.all.findIndex((f) => f.id === id)
- const previous = store.all[Math.max(0, index - 1)]
- setStore("active", previous?.id)
+ const next = index > 0 ? index - 1 : 0
+ setStore("active", filtered[next]?.id)
}
+ setStore("all", filtered)
})
+
await sdk.client.pty.remove({ ptyID: id }).catch((e) => {
console.error("Failed to close terminal", e)
})
@@ -244,6 +260,8 @@ export const { use: useTerminal, provider: TerminalProvider } = createSimpleCont
open: (id: string) => workspace().open(id),
close: (id: string) => workspace().close(id),
move: (id: string, to: number) => workspace().move(id, to),
+ next: () => workspace().next(),
+ previous: () => workspace().previous(),
}
},
})