Avoid terminal autostart on workspace switch

This commit is contained in:
Federico Jaramillo Martinez
2026-05-11 13:54:35 +02:00
parent 020b8f00ca
commit b07531cf3a
5 changed files with 11 additions and 3 deletions
+5 -1
View File
@@ -65,6 +65,7 @@ export class PiWebApp extends LitElement {
private readonly keyboard = new KeyboardShortcutDispatcher(); private readonly keyboard = new KeyboardShortcutDispatcher();
private readonly realtime = new RealtimeSocket(); private readonly realtime = new RealtimeSocket();
private readonly activeTerminalIds = new Set<string>(); private readonly activeTerminalIds = new Set<string>();
private terminalAutoStartWorkspaceId: string | undefined;
private readonly plugins = createPluginRegistry(); private readonly plugins = createPluginRegistry();
private readonly onPopState = () => void this.withChatScrollTransition(() => this.restoreRoute(false)); private readonly onPopState = () => void this.withChatScrollTransition(() => this.restoreRoute(false));
private readonly onKeyDown = (event: KeyboardEvent) => { private readonly onKeyDown = (event: KeyboardEvent) => {
@@ -151,6 +152,7 @@ export class PiWebApp extends LitElement {
} }
private selectWorkspaceTool(tool: QualifiedContributionId) { private selectWorkspaceTool(tool: QualifiedContributionId) {
if (tool === "core:workspace.terminal") this.terminalAutoStartWorkspaceId = this.state.selectedWorkspace?.id;
this.setState({ workspaceTool: tool, mainView: tool }); this.setState({ workspaceTool: tool, mainView: tool });
this.updateUrl(); this.updateUrl();
this.refreshSelectedWorkspaceTool(tool); this.refreshSelectedWorkspaceTool(tool);
@@ -172,6 +174,7 @@ export class PiWebApp extends LitElement {
private handleWorkspaceChange(previous: AppState, next: AppState) { private handleWorkspaceChange(previous: AppState, next: AppState) {
if (previous.selectedWorkspace?.id === next.selectedWorkspace?.id) return; if (previous.selectedWorkspace?.id === next.selectedWorkspace?.id) return;
this.terminalAutoStartWorkspaceId = undefined;
this.activeTerminalIds.clear(); this.activeTerminalIds.clear();
this.setState({ activeTerminalCount: 0 }); this.setState({ activeTerminalCount: 0 });
if (next.selectedWorkspace === undefined) return; if (next.selectedWorkspace === undefined) return;
@@ -235,7 +238,7 @@ export class PiWebApp extends LitElement {
private renderWorkspacePanel(hideToolTabs = false) { private renderWorkspacePanel(hideToolTabs = false) {
const workspaceLabelItems = this.state.selectedWorkspace === undefined ? [] : this.plugins.getWorkspaceLabelItems(this.state, this.state.selectedWorkspace); const workspaceLabelItems = this.state.selectedWorkspace === undefined ? [] : this.plugins.getWorkspaceLabelItems(this.state, this.state.selectedWorkspace);
return html`<workspace-panel .workspace=${this.state.selectedWorkspace} .tool=${this.state.workspaceTool} .panels=${this.visibleWorkspacePanels()} .workspaceLabelItems=${workspaceLabelItems} .hideToolTabs=${hideToolTabs} .fileTree=${this.state.fileTree} .expandedDirs=${this.state.expandedDirs} .selectedFilePath=${this.state.selectedFilePath} .selectedFileContent=${this.state.selectedFileContent} .fileTreeStale=${this.state.fileTreeStale} .gitStatus=${this.state.gitStatus} .selectedDiffPath=${this.state.selectedDiffPath} .selectedDiff=${this.state.selectedDiff} .selectedStagedDiff=${this.state.selectedStagedDiff} .gitStale=${this.state.gitStale} .activeTerminalCount=${this.state.activeTerminalCount} .onSelectTool=${(tool: QualifiedContributionId) => { 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)}></workspace-panel>`; return html`<workspace-panel .workspace=${this.state.selectedWorkspace} .tool=${this.state.workspaceTool} .panels=${this.visibleWorkspacePanels()} .workspaceLabelItems=${workspaceLabelItems} .hideToolTabs=${hideToolTabs} .fileTree=${this.state.fileTree} .expandedDirs=${this.state.expandedDirs} .selectedFilePath=${this.state.selectedFilePath} .selectedFileContent=${this.state.selectedFileContent} .fileTreeStale=${this.state.fileTreeStale} .gitStatus=${this.state.gitStatus} .selectedDiffPath=${this.state.selectedDiffPath} .selectedDiff=${this.state.selectedDiff} .selectedStagedDiff=${this.state.selectedStagedDiff} .gitStale=${this.state.gitStale} .activeTerminalCount=${this.state.activeTerminalCount} .terminalAutoStart=${this.terminalAutoStartWorkspaceId === this.state.selectedWorkspace?.id} .onSelectTool=${(tool: QualifiedContributionId) => { 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)}></workspace-panel>`;
} }
private renderNavigationPanel(autoSwitchToChat: boolean) { private renderNavigationPanel(autoSwitchToChat: boolean) {
@@ -282,6 +285,7 @@ export class PiWebApp extends LitElement {
selectedStagedDiff: this.state.selectedStagedDiff, selectedStagedDiff: this.state.selectedStagedDiff,
gitStale: this.state.gitStale, gitStale: this.state.gitStale,
activeTerminalCount: this.state.activeTerminalCount, activeTerminalCount: this.state.activeTerminalCount,
terminalAutoStart: this.terminalAutoStartWorkspaceId === workspace.id,
onRefreshFiles: () => { void this.files.refreshFiles(); }, onRefreshFiles: () => { void this.files.refreshFiles(); },
onExpandDir: (path: string) => { void this.files.expandDir(path); }, onExpandDir: (path: string) => { void this.files.expandDir(path); },
onSelectFile: (path: string) => { void this.files.selectFile(path); }, onSelectFile: (path: string) => { void this.files.selectFile(path); },
+2 -1
View File
@@ -8,6 +8,7 @@ import { terminalSocket, terminalsApi, type TerminalInfo, type Workspace } from
@customElement("terminal-panel") @customElement("terminal-panel")
export class TerminalPanel extends LitElement { export class TerminalPanel extends LitElement {
@property({ attribute: false }) workspace: Workspace | undefined; @property({ attribute: false }) workspace: Workspace | undefined;
@property({ type: Boolean }) autoStart = false;
@query(".terminal-host") private terminalHost?: HTMLDivElement; @query(".terminal-host") private terminalHost?: HTMLDivElement;
@state() private terminals: TerminalInfo[] = []; @state() private terminals: TerminalInfo[] = [];
@state() private selectedId: string | undefined; @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); const terminals = await terminalsApi.terminals(this.workspace.projectId, this.workspace.id);
this.terminals = terminals; this.terminals = terminals;
this.selectedId = terminals.find((terminal) => !terminal.exited)?.id ?? terminals[0]?.id; 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) { } catch (error) {
this.error = error instanceof Error ? error.message : String(error); this.error = error instanceof Error ? error.message : String(error);
} finally { } finally {
@@ -29,6 +29,7 @@ export class WorkspacePanel extends LitElement {
@property({ attribute: false }) onRefreshGit: () => void = () => undefined; @property({ attribute: false }) onRefreshGit: () => void = () => undefined;
@property({ attribute: false }) onSelectDiff: (path: string) => void = () => undefined; @property({ attribute: false }) onSelectDiff: (path: string) => void = () => undefined;
@property({ type: Number }) activeTerminalCount = 0; @property({ type: Number }) activeTerminalCount = 0;
@property({ type: Boolean }) terminalAutoStart = false;
override render() { override render() {
const workspace = this.workspace; const workspace = this.workspace;
@@ -75,6 +76,7 @@ export class WorkspacePanel extends LitElement {
selectedStagedDiff: this.selectedStagedDiff, selectedStagedDiff: this.selectedStagedDiff,
gitStale: this.gitStale, gitStale: this.gitStale,
activeTerminalCount: this.activeTerminalCount, activeTerminalCount: this.activeTerminalCount,
terminalAutoStart: this.terminalAutoStart,
onRefreshFiles: this.onRefreshFiles, onRefreshFiles: this.onRefreshFiles,
onExpandDir: this.onExpandDir, onExpandDir: this.onExpandDir,
onSelectFile: this.onSelectFile, onSelectFile: this.onSelectFile,
+1 -1
View File
@@ -76,7 +76,7 @@ function renderFileViewer(context: WorkspacePanelContext): TemplateResult {
function renderTerminal(context: WorkspacePanelContext): TemplateResult { function renderTerminal(context: WorkspacePanelContext): TemplateResult {
loadTerminalPanel(); loadTerminalPanel();
return html`<terminal-panel .workspace=${context.workspace}></terminal-panel>`; return html`<terminal-panel .workspace=${context.workspace} .autoStart=${context.terminalAutoStart}></terminal-panel>`;
} }
function renderGit(context: WorkspacePanelContext): TemplateResult { function renderGit(context: WorkspacePanelContext): TemplateResult {
+1
View File
@@ -65,6 +65,7 @@ export interface WorkspacePanelContext {
selectedStagedDiff: GitDiffResponse | undefined; selectedStagedDiff: GitDiffResponse | undefined;
gitStale: boolean; gitStale: boolean;
activeTerminalCount: number; activeTerminalCount: number;
terminalAutoStart: boolean;
onRefreshFiles: () => void; onRefreshFiles: () => void;
onExpandDir: (path: string) => void; onExpandDir: (path: string) => void;
onSelectFile: (path: string) => void; onSelectFile: (path: string) => void;