Skip to content

Commit bccd293

Browse files
Copilotalexr00
andauthored
Honor repository selection for PR and issue status bars (#8416)
* Initial plan * feat: honor repository selection for PR and issue status bars Listen to repository.ui.onDidChange event to track when the user switches between repositories. The PR status bar item and issue status bar item now show only when their respective repository is selected in the VS Code UI. Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * refactor: address code review feedback - Use definite assignment assertion for _isRepositorySelected field - Update updateStatusBarVisibility to also handle switching state Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * refactor: extract showStatusBarIfSelected method Extract the repeated pattern of checking _isRepositorySelected before showing the status bar into a dedicated private method. Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Revert some files --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent de14294 commit bccd293

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

src/view/reviewManager.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ export class ReviewManager extends Disposable {
8080
* Used to enter review mode for this PR regardless of its state (open/closed/merged).
8181
*/
8282
private _switchedToPullRequest?: PullRequestModel;
83+
/**
84+
* Track whether this repository is currently selected in the UI.
85+
* Used to show/hide the status bar item based on repository selection.
86+
*/
87+
private _isRepositorySelected!: boolean;
8388

8489
public get switchingToReviewMode(): boolean {
8590
return this._switchingToReviewMode;
@@ -109,6 +114,7 @@ export class ReviewManager extends Disposable {
109114
) {
110115
super();
111116
this._switchingToReviewMode = false;
117+
this._isRepositorySelected = _repository.ui.selected;
112118

113119
this._previousRepositoryState = {
114120
HEAD: _repository.state.HEAD,
@@ -190,6 +196,11 @@ export class ReviewManager extends Disposable {
190196
this.registerQuickDiff();
191197
}));
192198

199+
this._register(this._repository.ui.onDidChange(() => {
200+
this._isRepositorySelected = this._repository.ui.selected;
201+
this.updateStatusBarVisibility();
202+
}));
203+
193204
this._register(GitHubCreatePullRequestLinkProvider.registerProvider(this, this._folderRepoManager));
194205
}
195206

@@ -237,6 +248,30 @@ export class ReviewManager extends Disposable {
237248
return this._statusBarItem;
238249
}
239250

251+
/**
252+
* Updates the status bar visibility based on whether this repository is selected.
253+
* If there's an active PR (or switching to review mode) and the repository is selected, show the status bar.
254+
* Otherwise, hide it.
255+
*/
256+
private updateStatusBarVisibility() {
257+
if (this._statusBarItem) {
258+
if (this._isRepositorySelected && (this._folderRepoManager.activePullRequest || this._switchingToReviewMode)) {
259+
this._statusBarItem.show();
260+
} else {
261+
this._statusBarItem.hide();
262+
}
263+
}
264+
}
265+
266+
/**
267+
* Shows the status bar item only if this repository is currently selected.
268+
*/
269+
private showStatusBarIfSelected() {
270+
if (this._isRepositorySelected) {
271+
this.statusBarItem.show();
272+
}
273+
}
274+
240275
get repository(): Repository {
241276
return this._repository;
242277
}
@@ -562,7 +597,7 @@ export class ReviewManager extends Disposable {
562597
arguments: [pr],
563598
};
564599
Logger.appendLine(`Display pull request status bar indicator.`, this.id);
565-
this.statusBarItem.show();
600+
this.showStatusBarIfSelected();
566601

567602
this.layout(pr, updateLayout, this.justSwitchedToReviewMode ? false : silent);
568603
this.justSwitchedToReviewMode = false;
@@ -1116,7 +1151,7 @@ export class ReviewManager extends Disposable {
11161151
Logger.appendLine(`Switch to Pull Request #${pr.number} - start`, this.id);
11171152
this.statusBarItem.text = vscode.l10n.t('{0} Switching to Review Mode', '$(sync~spin)');
11181153
this.statusBarItem.command = undefined;
1119-
this.statusBarItem.show();
1154+
this.showStatusBarIfSelected();
11201155
this.switchingToReviewMode = true;
11211156
this._switchedToPullRequest = pr;
11221157

@@ -1165,7 +1200,7 @@ export class ReviewManager extends Disposable {
11651200
try {
11661201
this.statusBarItem.text = '$(sync~spin) ' + vscode.l10n.t('Fetching additional data: {0}', `pr/${pr.number}`);
11671202
this.statusBarItem.command = undefined;
1168-
this.statusBarItem.show();
1203+
this.showStatusBarIfSelected();
11691204

11701205
await this._folderRepoManager.fulfillPullRequestMissingInfo(pr);
11711206
this._upgradePullRequestEditors(pr);
@@ -1186,7 +1221,7 @@ export class ReviewManager extends Disposable {
11861221
this.justSwitchedToReviewMode = true;
11871222
this.statusBarItem.text = vscode.l10n.t('Pull Request #{0}', pr.number);
11881223
this.statusBarItem.command = undefined;
1189-
this.statusBarItem.show();
1224+
this.showStatusBarIfSelected();
11901225
}
11911226

11921227
public async createPullRequest(compareBranch?: string): Promise<void> {

0 commit comments

Comments
 (0)