From b07531cf3a91ab3d2d4e874f66ab1e3451ffed7e Mon Sep 17 00:00:00 2001 From: Federico Jaramillo Martinez Date: Mon, 11 May 2026 13:54:35 +0200 Subject: [PATCH] Avoid terminal autostart on workspace switch --- src/client/src/components/PiWebApp.ts | 6 +++++- src/client/src/components/TerminalPanel.ts | 3 ++- src/client/src/components/WorkspacePanel.ts | 2 ++ src/client/src/plugins/core/panels.ts | 2 +- src/client/src/plugins/types.ts | 1 + 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/client/src/components/PiWebApp.ts b/src/client/src/components/PiWebApp.ts index 9c975a3..71b6ff2 100644 --- a/src/client/src/components/PiWebApp.ts +++ b/src/client/src/components/PiWebApp.ts @@ -65,6 +65,7 @@ export class PiWebApp extends LitElement { private readonly keyboard = new KeyboardShortcutDispatcher(); private readonly realtime = new RealtimeSocket(); private readonly activeTerminalIds = new Set(); + private terminalAutoStartWorkspaceId: string | undefined; private readonly plugins = createPluginRegistry(); private readonly onPopState = () => void this.withChatScrollTransition(() => this.restoreRoute(false)); private readonly onKeyDown = (event: KeyboardEvent) => { @@ -151,6 +152,7 @@ export class PiWebApp extends LitElement { } private selectWorkspaceTool(tool: QualifiedContributionId) { + if (tool === "core:workspace.terminal") this.terminalAutoStartWorkspaceId = this.state.selectedWorkspace?.id; this.setState({ workspaceTool: tool, mainView: tool }); this.updateUrl(); this.refreshSelectedWorkspaceTool(tool); @@ -172,6 +174,7 @@ export class PiWebApp extends LitElement { private handleWorkspaceChange(previous: AppState, next: AppState) { if (previous.selectedWorkspace?.id === next.selectedWorkspace?.id) return; + this.terminalAutoStartWorkspaceId = undefined; this.activeTerminalIds.clear(); this.setState({ activeTerminalCount: 0 }); if (next.selectedWorkspace === undefined) return; @@ -235,7 +238,7 @@ export class PiWebApp extends LitElement { private renderWorkspacePanel(hideToolTabs = false) { const workspaceLabelItems = this.state.selectedWorkspace === undefined ? [] : this.plugins.getWorkspaceLabelItems(this.state, this.state.selectedWorkspace); - return html` { this.selectWorkspaceTool(tool); }} .onRefreshFiles=${() => this.files.refreshFiles()} .onExpandDir=${(path: string) => this.files.expandDir(path)} .onSelectFile=${(path: string) => this.files.selectFile(path)} .onRefreshGit=${() => this.git.refreshGit()} .onSelectDiff=${(path: string) => this.git.selectDiff(path)}>`; + return html` { this.selectWorkspaceTool(tool); }} .onRefreshFiles=${() => this.files.refreshFiles()} .onExpandDir=${(path: string) => this.files.expandDir(path)} .onSelectFile=${(path: string) => this.files.selectFile(path)} .onRefreshGit=${() => this.git.refreshGit()} .onSelectDiff=${(path: string) => this.git.selectDiff(path)}>`; } private renderNavigationPanel(autoSwitchToChat: boolean) { @@ -282,6 +285,7 @@ export class PiWebApp extends LitElement { selectedStagedDiff: this.state.selectedStagedDiff, gitStale: this.state.gitStale, activeTerminalCount: this.state.activeTerminalCount, + terminalAutoStart: this.terminalAutoStartWorkspaceId === workspace.id, onRefreshFiles: () => { void this.files.refreshFiles(); }, onExpandDir: (path: string) => { void this.files.expandDir(path); }, onSelectFile: (path: string) => { void this.files.selectFile(path); }, diff --git a/src/client/src/components/TerminalPanel.ts b/src/client/src/components/TerminalPanel.ts index 5c23637..d455522 100644 --- a/src/client/src/components/TerminalPanel.ts +++ b/src/client/src/components/TerminalPanel.ts @@ -8,6 +8,7 @@ import { terminalSocket, terminalsApi, type TerminalInfo, type Workspace } from @customElement("terminal-panel") export class TerminalPanel extends LitElement { @property({ attribute: false }) workspace: Workspace | undefined; + @property({ type: Boolean }) autoStart = false; @query(".terminal-host") private terminalHost?: HTMLDivElement; @state() private terminals: TerminalInfo[] = []; @state() private selectedId: string | undefined; @@ -68,7 +69,7 @@ export class TerminalPanel extends LitElement { const terminals = await terminalsApi.terminals(this.workspace.projectId, this.workspace.id); this.terminals = terminals; this.selectedId = terminals.find((terminal) => !terminal.exited)?.id ?? terminals[0]?.id; - if (terminals.length === 0) await this.startTerminal(); + if (terminals.length === 0 && this.autoStart) await this.startTerminal(); } catch (error) { this.error = error instanceof Error ? error.message : String(error); } finally { diff --git a/src/client/src/components/WorkspacePanel.ts b/src/client/src/components/WorkspacePanel.ts index b5b281a..f57dc9a 100644 --- a/src/client/src/components/WorkspacePanel.ts +++ b/src/client/src/components/WorkspacePanel.ts @@ -29,6 +29,7 @@ export class WorkspacePanel extends LitElement { @property({ attribute: false }) onRefreshGit: () => void = () => undefined; @property({ attribute: false }) onSelectDiff: (path: string) => void = () => undefined; @property({ type: Number }) activeTerminalCount = 0; + @property({ type: Boolean }) terminalAutoStart = false; override render() { const workspace = this.workspace; @@ -75,6 +76,7 @@ export class WorkspacePanel extends LitElement { selectedStagedDiff: this.selectedStagedDiff, gitStale: this.gitStale, activeTerminalCount: this.activeTerminalCount, + terminalAutoStart: this.terminalAutoStart, onRefreshFiles: this.onRefreshFiles, onExpandDir: this.onExpandDir, onSelectFile: this.onSelectFile, diff --git a/src/client/src/plugins/core/panels.ts b/src/client/src/plugins/core/panels.ts index cced505..ff2005b 100644 --- a/src/client/src/plugins/core/panels.ts +++ b/src/client/src/plugins/core/panels.ts @@ -76,7 +76,7 @@ function renderFileViewer(context: WorkspacePanelContext): TemplateResult { function renderTerminal(context: WorkspacePanelContext): TemplateResult { loadTerminalPanel(); - return html``; + return html``; } function renderGit(context: WorkspacePanelContext): TemplateResult { diff --git a/src/client/src/plugins/types.ts b/src/client/src/plugins/types.ts index e95c227..a557b12 100644 --- a/src/client/src/plugins/types.ts +++ b/src/client/src/plugins/types.ts @@ -65,6 +65,7 @@ export interface WorkspacePanelContext { selectedStagedDiff: GitDiffResponse | undefined; gitStale: boolean; activeTerminalCount: number; + terminalAutoStart: boolean; onRefreshFiles: () => void; onExpandDir: (path: string) => void; onSelectFile: (path: string) => void;