From 620cef7a316013846150f3a2d519b218ead788ff Mon Sep 17 00:00:00 2001 From: Sebastian Barfurth Date: Wed, 11 Feb 2026 05:43:53 +0000 Subject: [PATCH] Prevent switching the view to SCM view after changes. --- src/graphTreeView.ts | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/graphTreeView.ts b/src/graphTreeView.ts index 4ca95fc..a4c53e9 100644 --- a/src/graphTreeView.ts +++ b/src/graphTreeView.ts @@ -51,6 +51,14 @@ export class GraphTreeView { treeDataProvider: this.treeDataProvider, }); this.updateTitle(this.treeDataProvider.getSelectedRepo().repositoryRoot); + this.graphTreeView.onDidChangeVisibility((e) => { + // Update the selection whenver the tree view becomes visible. We cannot + // do any selection updates while the view is hidden since would cause + // disruptive panel switching. + if (e.visible) { + void this.treeDataProvider.updateSelection(this.graphTreeView); + } + }); this.subscriptions.push(this.graphTreeView); } @@ -157,6 +165,7 @@ export class GraphTreeDataProvider implements TreeDataProvider { private items: GraphTreeItem[] = []; private itemChangeIds = new Set(); + private workingCopyChange: ChangeWithDetails | undefined; constructor(private selectedRepository: JJRepository) {} @@ -193,14 +202,10 @@ export class GraphTreeDataProvider implements TreeDataProvider { ); const items: GraphTreeItem[] = []; const itemChangeIds = new Set(); - const itemsToSelect: GraphTreeItem[] = []; - const workingCopyParents = new Set( - results.find((r) => r.change.isCurrentWorkingCopy)?.change - .parentChangeIds, - ); for (const result of results) { // Don't render the working copy in the graph. if (result.change.isCurrentWorkingCopy) { + this.workingCopyChange = result.change; continue; } const childrenChangeIds = results @@ -213,9 +218,6 @@ export class GraphTreeDataProvider implements TreeDataProvider { const item = new GraphTreeItem(result.change, childrenChangeIds, this); items.push(item); itemChangeIds.add(result.change.changeId); - if (workingCopyParents.has(item.getChangeId())) { - itemsToSelect.push(item); - } } this.items = items; this.itemChangeIds = itemChangeIds; @@ -225,9 +227,7 @@ export class GraphTreeDataProvider implements TreeDataProvider { ) { this.onDidChangeTreeDataInternal.fire(); } - for (const item of itemsToSelect) { - await treeView.reveal(item, { select: true }); - } + await this.updateSelection(treeView); } async setSelectedRepo(repo: JJRepository, treeView: TreeView) { @@ -249,4 +249,18 @@ export class GraphTreeDataProvider implements TreeDataProvider { } return this.items.find((item) => item.getChangeId() === parentChangeIds[0]); } + + async updateSelection(treeView: TreeView) { + // Only reveal items if the tree view is currently visible. Otherwise we + // would end up potentially switching panels in the sidebar. We always + // perform automatic re-selection on visibility change. + if (!treeView.visible || !this.workingCopyChange) { + return; + } + for (const item of this.items) { + if (this.workingCopyChange.parentChangeIds.includes(item.getChangeId())) { + await treeView.reveal(item, { select: true, focus: false }); + } + } + } }