Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/view/treeNodes/filesCategoryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ export class FilesCategoryNode extends TreeNode implements vscode.TreeItem {
} else {
const fileNodes = [...filesToShow];
fileNodes.sort((a, b) => compareIgnoreCase(a.fileChangeResourceUri.toString(), b.fileChangeResourceUri.toString()));
// In flat layout, files are rendered as direct children of this node.
// Keep parent pointers aligned with the rendered hierarchy so reveal/getParent
// don't try to walk through hidden DirectoryTreeNode instances.
fileNodes.forEach(fileNode => {
fileNode.parent = this;
});
nodes = fileNodes;
}
Logger.appendLine(`Got all children for Files node`, PR_TREE);
Expand Down
16 changes: 14 additions & 2 deletions src/view/treeNodes/repositoryChangesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class RepositoryChangesNode extends TreeNode implements vscode.TreeItem {
this.getTreeItem();

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

this._register(this.parent.view.onDidChangeVisibility(_ => {
if (!this.isFileAutoRevealEnabled()) {
return;
}
const activeEditorUri = vscode.window.activeTextEditor?.document.uri.toString();
this.revealActiveEditorInTree(activeEditorUri);
}));
Expand All @@ -77,10 +80,19 @@ export class RepositoryChangesNode extends TreeNode implements vscode.TreeItem {
}));
}

private isFileAutoRevealEnabled(): boolean {
return vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(FILE_AUTO_REVEAL, true);
}

private revealActiveEditorInTree(activeEditorUri: string | undefined): void {
// File nodes are wired into the tree when FilesCategoryNode children are built.
// Skip reveal attempts before that to avoid invalid handle lookups.
if (!this._filesCategoryNode) {
return;
}
if (this.parent.view.visible && activeEditorUri) {
const matchingFile = this._reviewModel.localFileChanges.find(change => change.changeModel.filePath.toString() === activeEditorUri);
if (matchingFile) {
if (matchingFile && matchingFile.parent !== this.parent) {
this.reveal(matchingFile, { select: true });
}
}
Expand Down