From b70e2b3402ead68bbaa0aec8f7e2b0823f3cc615 Mon Sep 17 00:00:00 2001 From: pratyushsinghal7 Date: Thu, 23 Jul 2026 15:47:13 -0700 Subject: [PATCH 1/3] Add option to keep viewed files open --- src/commands.ts | 30 ++++++++++++++++++------------ src/test/extension.test.ts | 15 +++++++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index 79f4303e59..4bbdd59ebb 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1798,9 +1798,13 @@ ${contents} }; context.subscriptions.push( - vscode.commands.registerCommand('pr.markFileAsViewed', async (treeNode: FileChangeNode | vscode.Uri | undefined) => { + vscode.commands.registerCommand('pr.markFileAsViewed', async (treeNodeOrOptions: FileChangeNode | vscode.Uri | { dontCloseFile: boolean } | undefined, options?: { dontCloseFile: boolean }) => { try { - if (treeNode === undefined) { + let treeNode: FileChangeNode | vscode.Uri | undefined; + if (treeNodeOrOptions instanceof FileChangeNode || treeNodeOrOptions instanceof vscode.Uri) { + treeNode = treeNodeOrOptions; + } else { + options = treeNodeOrOptions; // Use the active editor to enable keybindings treeNode = vscode.window.activeTextEditor?.document.uri; } @@ -1810,16 +1814,18 @@ ${contents} } else if (treeNode) { // When the argument is a uri it came from the editor menu and we should also close the file // Do the close first to improve perceived performance of marking as viewed. - const tab = vscode.window.tabGroups.activeTabGroup.activeTab; - if (tab) { - let compareUri: vscode.Uri | undefined = undefined; - if (tab.input instanceof vscode.TabInputTextDiff) { - compareUri = tab.input.modified; - } else if (tab.input instanceof vscode.TabInputText) { - compareUri = tab.input.uri; - } - if (compareUri && treeNode.toString() === compareUri.toString()) { - vscode.window.tabGroups.close(tab); + if (!options?.dontCloseFile) { + const tab = vscode.window.tabGroups.activeTabGroup.activeTab; + if (tab) { + let compareUri: vscode.Uri | undefined = undefined; + if (tab.input instanceof vscode.TabInputTextDiff) { + compareUri = tab.input.modified; + } else if (tab.input instanceof vscode.TabInputText) { + compareUri = tab.input.uri; + } + if (compareUri && treeNode.toString() === compareUri.toString()) { + vscode.window.tabGroups.close(tab); + } } } diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 3038c33295..0785467817 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -1,7 +1,22 @@ import { default as assert } from 'assert'; +import * as vscode from 'vscode'; import { parseDiffHunk } from '../common/diffHunk'; describe('Extension Tests', function () { + describe('markFileAsViewed', () => { + it('should keep the active editor open when dontCloseFile is true', async () => { + const document = await vscode.workspace.openTextDocument({ content: 'test' }); + await vscode.window.showTextDocument(document); + const tab = vscode.window.tabGroups.activeTabGroup.activeTab; + assert.ok(tab); + + await vscode.commands.executeCommand('pr.markFileAsViewed', { dontCloseFile: true }); + + assert.strictEqual(vscode.window.tabGroups.activeTabGroup.activeTab, tab); + await vscode.window.tabGroups.close(tab); + }); + }); + describe('parseDiffHunk', () => { it('should handle empty string', () => { const diffHunk = parseDiffHunk(''); From 019ce92f2ff1c001a0940923bc11eecba922e088 Mon Sep 17 00:00:00 2001 From: pratyushsinghal7 Date: Thu, 23 Jul 2026 16:00:38 -0700 Subject: [PATCH 2/3] Address mark viewed review feedback --- src/commands.ts | 2 +- src/test/extension.test.ts | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index 4bbdd59ebb..9ed29e4b64 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1804,7 +1804,7 @@ ${contents} if (treeNodeOrOptions instanceof FileChangeNode || treeNodeOrOptions instanceof vscode.Uri) { treeNode = treeNodeOrOptions; } else { - options = treeNodeOrOptions; + options = treeNodeOrOptions ?? options; // Use the active editor to enable keybindings treeNode = vscode.window.activeTextEditor?.document.uri; } diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 0785467817..b7881d133b 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -4,16 +4,26 @@ import { parseDiffHunk } from '../common/diffHunk'; describe('Extension Tests', function () { describe('markFileAsViewed', () => { - it('should keep the active editor open when dontCloseFile is true', async () => { + async function assertCommandKeepsTabOpen(...args: unknown[]) { const document = await vscode.workspace.openTextDocument({ content: 'test' }); await vscode.window.showTextDocument(document); const tab = vscode.window.tabGroups.activeTabGroup.activeTab; assert.ok(tab); - await vscode.commands.executeCommand('pr.markFileAsViewed', { dontCloseFile: true }); + try { + await vscode.commands.executeCommand('pr.markFileAsViewed', ...args); + assert.strictEqual(vscode.window.tabGroups.activeTabGroup.activeTab, tab); + } finally { + await vscode.window.tabGroups.close(tab); + } + } - assert.strictEqual(vscode.window.tabGroups.activeTabGroup.activeTab, tab); - await vscode.window.tabGroups.close(tab); + it('should keep the active editor open with keybinding options', async () => { + await assertCommandKeepsTabOpen({ dontCloseFile: true }); + }); + + it('should keep the active editor open with options as the second argument', async () => { + await assertCommandKeepsTabOpen(undefined, { dontCloseFile: true }); }); }); From 3df5e41feff458b5c56fb6e05be29a5b4bc7d5f0 Mon Sep 17 00:00:00 2001 From: pratyushsinghal7 Date: Thu, 23 Jul 2026 16:09:56 -0700 Subject: [PATCH 3/3] Cover URI mark viewed options --- src/test/extension.test.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index b7881d133b..e9c45abbe2 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -4,14 +4,14 @@ import { parseDiffHunk } from '../common/diffHunk'; describe('Extension Tests', function () { describe('markFileAsViewed', () => { - async function assertCommandKeepsTabOpen(...args: unknown[]) { + async function assertCommandKeepsTabOpen(getArgs: (uri: vscode.Uri) => unknown[]) { const document = await vscode.workspace.openTextDocument({ content: 'test' }); await vscode.window.showTextDocument(document); const tab = vscode.window.tabGroups.activeTabGroup.activeTab; assert.ok(tab); try { - await vscode.commands.executeCommand('pr.markFileAsViewed', ...args); + await vscode.commands.executeCommand('pr.markFileAsViewed', ...getArgs(document.uri)); assert.strictEqual(vscode.window.tabGroups.activeTabGroup.activeTab, tab); } finally { await vscode.window.tabGroups.close(tab); @@ -19,11 +19,15 @@ describe('Extension Tests', function () { } it('should keep the active editor open with keybinding options', async () => { - await assertCommandKeepsTabOpen({ dontCloseFile: true }); + await assertCommandKeepsTabOpen(() => [{ dontCloseFile: true }]); }); it('should keep the active editor open with options as the second argument', async () => { - await assertCommandKeepsTabOpen(undefined, { dontCloseFile: true }); + await assertCommandKeepsTabOpen(() => [undefined, { dontCloseFile: true }]); + }); + + it('should keep the active editor open with a URI and options', async () => { + await assertCommandKeepsTabOpen(uri => [uri, { dontCloseFile: true }]); }); });