Skip to content

Commit 6eb81cf

Browse files
committed
Don't move selection if already correct and avoid unneeded refresh
1 parent 08d4f4c commit 6eb81cf

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/view/prsTreeDataProvider.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,15 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
184184
* Sync the tree view with the currently active PR overview
185185
*/
186186
private async syncWithActivePullRequest(pullRequest: PullRequestModel): Promise<void> {
187+
const alreadySelected = this._view.selection.find(child => child instanceof PRNode && (child.pullRequestModel.number === pullRequest.number) && (child.pullRequestModel.remote.owner === pullRequest.remote.owner) && (child.pullRequestModel.remote.repositoryName === pullRequest.remote.repositoryName));
188+
if (alreadySelected || !this._view.visible) {
189+
return;
190+
}
187191
try {
188-
// First expand the pull request in the tree to make sure it's visible
189-
await this.expandPullRequest(pullRequest);
190-
191192
// Find the PR node in the tree and reveal it
192193
const prNode = await this.findPRNode(pullRequest);
193194
if (prNode) {
194-
await this.reveal(prNode, { select: true, focus: false, expand: true });
195+
await this.reveal(prNode, { select: true, focus: false, expand: false });
195196
}
196197
} catch (error) {
197198
// Silently ignore errors to avoid disrupting the user experience
@@ -223,7 +224,7 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
223224
* Search for PR node within a workspace folder node
224225
*/
225226
private async findPRNodeInWorkspaceFolder(workspaceNode: WorkspaceFolderNode, pullRequest: PullRequestModel): Promise<PRNode | undefined> {
226-
const children = await workspaceNode.getChildren();
227+
const children = await workspaceNode.getChildren(false);
227228
for (const child of children) {
228229
if (child instanceof CategoryTreeNode) {
229230
const found = await this.findPRNodeInCategory(child, pullRequest);
@@ -237,9 +238,9 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
237238
* Search for PR node within a category node
238239
*/
239240
private async findPRNodeInCategory(categoryNode: CategoryTreeNode, pullRequest: PullRequestModel): Promise<PRNode | undefined> {
240-
const children = await categoryNode.getChildren();
241+
const children = await categoryNode.getChildren(false);
241242
for (const child of children) {
242-
if (child instanceof PRNode && child.pullRequestModel.number === pullRequest.number) {
243+
if (child instanceof PRNode && (child.pullRequestModel.number === pullRequest.number) && (child.pullRequestModel.remote.owner === pullRequest.remote.owner) && (child.pullRequestModel.remote.repositoryName === pullRequest.remote.repositoryName)) {
243244
return child;
244245
}
245246
}

src/view/treeNodes/categoryNode.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,11 @@ export class CategoryTreeNode extends TreeNode implements vscode.TreeItem {
207207
return false;
208208
}
209209

210-
override async getChildren(): Promise<TreeNode[]> {
211-
await super.getChildren();
210+
override async getChildren(shouldDispose: boolean = true): Promise<TreeNode[]> {
211+
await super.getChildren(shouldDispose);
212+
if (!shouldDispose && this.children) {
213+
return this.children;
214+
}
212215
const isFirstLoad = !this._firstLoad;
213216
if (isFirstLoad) {
214217
this._firstLoad = this.doGetChildren();

src/view/treeNodes/workspaceFolderNode.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ export class WorkspaceFolderNode extends TreeNode implements vscode.TreeItem {
6363
return this;
6464
}
6565

66-
override async getChildren(): Promise<TreeNode[]> {
67-
super.getChildren();
66+
override async getChildren(shouldDispose: boolean = true): Promise<TreeNode[]> {
67+
super.getChildren(shouldDispose);
68+
if (!shouldDispose && this.children) {
69+
return this.children;
70+
}
6871
this.children = await WorkspaceFolderNode.getCategoryTreeNodes(this.folderManager, this.telemetry, this, this.notificationProvider, this.context, this._prsTreeModel, this._copilotMananger);
6972
return this.children;
7073
}

0 commit comments

Comments
 (0)