Skip to content

Commit 868b6cb

Browse files
gvilumsalexr00
andauthored
Fix PR tree reveal failures for flat file layout (#8522)
- Re-parent file nodes to FilesCategoryNode when rendering flat layout so tree handles stay consistent. - Honor fileAutoReveal on tree visibility changes and guard reveal until Files node is initialized. - Avoid reveal calls when a file node is already attached to the tree root parent. Co-authored-by: Alex Ross <38270282+alexr00@users.noreply.github.com>
1 parent 7841c9d commit 868b6cb

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/view/treeNodes/filesCategoryNode.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ export class FilesCategoryNode extends TreeNode implements vscode.TreeItem {
102102
} else {
103103
const fileNodes = [...filesToShow];
104104
fileNodes.sort((a, b) => compareIgnoreCase(a.fileChangeResourceUri.toString(), b.fileChangeResourceUri.toString()));
105+
// In flat layout, files are rendered as direct children of this node.
106+
// Keep parent pointers aligned with the rendered hierarchy so reveal/getParent
107+
// don't try to walk through hidden DirectoryTreeNode instances.
108+
fileNodes.forEach(fileNode => {
109+
fileNode.parent = this;
110+
});
105111
nodes = fileNodes;
106112
}
107113
Logger.appendLine(`Got all children for Files node`, PR_TREE);

src/view/treeNodes/repositoryChangesNode.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class RepositoryChangesNode extends TreeNode implements vscode.TreeItem {
5151
this.getTreeItem();
5252

5353
this._register(vscode.window.onDidChangeActiveTextEditor(e => {
54-
if (vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get(FILE_AUTO_REVEAL)) {
54+
if (this.isFileAutoRevealEnabled()) {
5555
const tabInput = vscode.window.tabGroups.activeTabGroup.activeTab?.input;
5656
if (tabInput instanceof vscode.TabInputTextDiff) {
5757
if ((tabInput.original.scheme === Schemes.Review)
@@ -66,6 +66,9 @@ export class RepositoryChangesNode extends TreeNode implements vscode.TreeItem {
6666
}));
6767

6868
this._register(this.parent.view.onDidChangeVisibility(_ => {
69+
if (!this.isFileAutoRevealEnabled()) {
70+
return;
71+
}
6972
const activeEditorUri = vscode.window.activeTextEditor?.document.uri.toString();
7073
this.revealActiveEditorInTree(activeEditorUri);
7174
}));
@@ -77,10 +80,19 @@ export class RepositoryChangesNode extends TreeNode implements vscode.TreeItem {
7780
}));
7881
}
7982

83+
private isFileAutoRevealEnabled(): boolean {
84+
return vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(FILE_AUTO_REVEAL, true);
85+
}
86+
8087
private revealActiveEditorInTree(activeEditorUri: string | undefined): void {
88+
// File nodes are wired into the tree when FilesCategoryNode children are built.
89+
// Skip reveal attempts before that to avoid invalid handle lookups.
90+
if (!this._filesCategoryNode) {
91+
return;
92+
}
8193
if (this.parent.view.visible && activeEditorUri) {
8294
const matchingFile = this._reviewModel.localFileChanges.find(change => change.changeModel.filePath.toString() === activeEditorUri);
83-
if (matchingFile) {
95+
if (matchingFile && matchingFile.parent !== this.parent) {
8496
this.reveal(matchingFile, { select: true });
8597
}
8698
}

0 commit comments

Comments
 (0)