From 87d91c29e23d136436342542f83a20bfc4a3d0bf Mon Sep 17 00:00:00 2001 From: Halil Tezcan KARABULUT Date: Wed, 21 Jan 2026 15:49:46 +0300 Subject: fix(app): terminal improvements - focus, rename, error state, CSP (#9700) --- packages/app/src/context/terminal.tsx | 48 ++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 15 deletions(-) (limited to 'packages/app/src/context') 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, 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, dir: string, sess }) }, update(pty: Partial & { 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, 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(), } }, }) -- cgit v1.2.3