From de8121c0d9a180b690942703b28f2050756e41ab Mon Sep 17 00:00:00 2001 From: Alex Ross <38270282+alexr00@users.noreply.github.com> Date: Tue, 14 Jul 2026 14:29:05 +0200 Subject: [PATCH] Try to fix focus view showing on git commands --- src/test/view/reviewManager.test.ts | 25 ++++++++++++++++++++++++- src/view/reviewManager.ts | 15 +++++++++------ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/test/view/reviewManager.test.ts b/src/test/view/reviewManager.test.ts index 9d47032089..1885f6ff54 100644 --- a/src/test/view/reviewManager.test.ts +++ b/src/test/view/reviewManager.test.ts @@ -17,6 +17,7 @@ import { PullRequestChangesTreeDataProvider } from '../../view/prChangesTreeData import { PullRequestsTreeDataProvider } from '../../view/prsTreeDataProvider'; import { ReviewManager, ShowPullRequest } from '../../view/reviewManager'; import { WebviewViewCoordinator } from '../../view/webviewViewCoordinator'; +import { FOCUS_REVIEW_MODE } from '../../constants'; import { MockPrsTreeModel } from '../mocks/mockPRsTreeModel'; import { MockCommandRegistry } from '../mocks/mockCommandRegistry'; import { MockExtensionContext } from '../mocks/mockExtensionContext'; @@ -39,6 +40,7 @@ describe('ReviewManager polling', function () { let gitApi: GitApiImpl; let manager: FolderRepositoryManager; let reviewManager: ReviewManager; + let showPullRequest: ShowPullRequest; let onDidChangeWindowStateCallback: ((state: vscode.WindowState) => unknown) | undefined; let isWindowFocused: boolean; let setTimeoutSpy: sinon.SinonSpy; @@ -75,6 +77,7 @@ describe('ReviewManager polling', function () { reposManager.insertFolderManager(manager); const changesTreeProvider = new PullRequestChangesTreeDataProvider(gitApi, reposManager); + showPullRequest = new ShowPullRequest(); reviewManager = new ReviewManager( 0, context, @@ -83,7 +86,7 @@ describe('ReviewManager polling', function () { telemetry, changesTreeProvider, prsTreeProvider, - new ShowPullRequest(), + showPullRequest, activePrViewCoordinator, createPrHelper, gitApi, @@ -211,4 +214,24 @@ describe('ReviewManager polling', function () { await flushMicrotasks(); assert.strictEqual(latestScheduledDelay(), POLL_MIN_INTERVAL_MS * 6); }); + + it('shows a deferred pull request reveal only once', async function () { + await context.workspaceState.update(FOCUS_REVIEW_MODE, true); + const pullRequest = {} as PullRequestModel; + const reviewManagerLayout = reviewManager as unknown as { + layout(pr: PullRequestModel, updateLayout: boolean, silent: boolean): void; + _doFocusShow(pr: PullRequestModel, updateLayout: boolean): void; + }; + const focusShow = sinon.stub(reviewManagerLayout, '_doFocusShow'); + + reviewManagerLayout.layout(pullRequest, true, true); + showPullRequest.shouldShow = true; + + assert.strictEqual(focusShow.callCount, 1); + assert.deepStrictEqual(focusShow.firstCall.args, [pullRequest, true]); + + reviewManagerLayout.layout(pullRequest, true, true); + + assert.strictEqual(focusShow.callCount, 1); + }); }); diff --git a/src/view/reviewManager.ts b/src/view/reviewManager.ts index 72b6245075..86a0ecd6ca 100644 --- a/src/view/reviewManager.ts +++ b/src/view/reviewManager.ts @@ -797,17 +797,18 @@ export class ReviewManager extends Disposable { private layout(pr: PullRequestModel, updateLayout: boolean, silent: boolean) { const isFocusMode = this._context.workspaceState.get(FOCUS_REVIEW_MODE); + const shouldShow = isFocusMode ? this._showPullRequest.takeShouldShow() : false; Logger.appendLine(`Using focus mode = ${isFocusMode}.`, this.id); Logger.appendLine(`State validation silent = ${silent}.`, this.id); - Logger.appendLine(`PR show should show = ${this._showPullRequest.shouldShow}.`, this.id); + Logger.appendLine(`PR show should show = ${shouldShow}.`, this.id); - if ((!silent || this._showPullRequest.shouldShow) && isFocusMode) { + if ((!silent || shouldShow) && isFocusMode) { this._doFocusShow(pr, updateLayout); - } else if (!this._showPullRequest.shouldShow && isFocusMode) { + } else if (isFocusMode) { const showPRChangedDisposable = this._showPullRequest.onChangedShowValue(shouldShow => { Logger.appendLine(`PR show value changed = ${shouldShow}.`, this.id); - if (shouldShow) { + if (shouldShow && this._showPullRequest.takeShouldShow()) { this._doFocusShow(pr, updateLayout); } showPRChangedDisposable.dispose(); @@ -1612,8 +1613,10 @@ export class ShowPullRequest { private _onChangedShowValue: vscode.EventEmitter = new vscode.EventEmitter(); public readonly onChangedShowValue: vscode.Event = this._onChangedShowValue.event; constructor() { } - get shouldShow(): boolean { - return this._shouldShow; + takeShouldShow(): boolean { + const shouldShow = this._shouldShow; + this._shouldShow = false; + return shouldShow; } set shouldShow(shouldShow: boolean) { const oldShowValue = this._shouldShow;