Skip to content

Commit 71050cf

Browse files
authored
Command to close all 'pull request related' editors (#6459)
* Command to close all 'pull request related' editors Fixes #6234 * Fix command palette visibility * Fix extra pr.
1 parent 5155eb8 commit 71050cf

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,11 @@
11901190
"title": "%command.pr.acceptMerge.title%",
11911191
"category": "%command.pull.request.category%"
11921192
},
1193+
{
1194+
"command": "pr.closeRelatedEditors",
1195+
"title": "%command.pr.closeRelatedEditors.title%",
1196+
"category": "%command.pull.request.category%"
1197+
},
11931198
{
11941199
"command": "review.diffWithPrHead",
11951200
"title": "%command.review.diffWithPrHead.title%",
@@ -1776,6 +1781,10 @@
17761781
"command": "pr.showDiffAll",
17771782
"when": "false"
17781783
},
1784+
{
1785+
"command": "pr.closeRelatedEditors",
1786+
"when": "gitHubOpenRepositoryCount != 0"
1787+
},
17791788
{
17801789
"command": "review.suggestDiff",
17811790
"when": "false"
@@ -2908,6 +2917,13 @@
29082917
"group": "1_cutcopypaste@0"
29092918
}
29102919
],
2920+
"editor/title/context": [
2921+
{
2922+
"command": "pr.closeRelatedEditors",
2923+
"when": "resourceScheme == 'pr' || resourceScheme == 'review' || resourcePath in github:unviewedFiles || resourcePath in github:viewedFiles",
2924+
"group": "1_close@60"
2925+
}
2926+
],
29112927
"editor/title/context/share": [
29122928
{
29132929
"command": "issue.copyGithubPermalinkWithoutRange",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@
255255
"command.pr.refreshComments.title": "Refresh Pull Request Comments",
256256
"command.pr.resolveConflict.title": "Resolve Conflict",
257257
"command.pr.acceptMerge.title": "Accept Merge",
258+
"command.pr.closeRelatedEditors.title": "Close All Pull Request Editors",
258259
"command.issue.copyGithubDevLink.title": "Copy github.dev Link",
259260
"command.issue.copyGithubPermalink.title": "Copy GitHub Permalink",
260261
"command.issue.copyGithubHeadLink.title": "Copy GitHub Head Link",

src/commands.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ export async function openPullRequestOnGitHub(e: PRNode | DescriptionNode | Pull
129129
telemetry.sendTelemetryEvent('pr.openInGitHub');
130130
}
131131

132+
export async function closeAllPrAndReviewEditors() {
133+
const tabs = vscode.window.tabGroups;
134+
const editors = tabs.all.map(group => group.tabs).flat();
135+
136+
for (const tab of editors) {
137+
const scheme = tab.input instanceof vscode.TabInputTextDiff ? tab.input.original.scheme : (tab.input instanceof vscode.TabInputText ? tab.input.uri.scheme : undefined);
138+
if (scheme && (scheme === Schemes.Pr) || (scheme === Schemes.Review)) {
139+
await tabs.close(tab);
140+
}
141+
}
142+
}
143+
132144
export function registerCommands(
133145
context: vscode.ExtensionContext,
134146
reposManager: RepositoriesManager,
@@ -1614,4 +1626,8 @@ ${contents}
16141626
}
16151627
}
16161628
}));
1629+
1630+
context.subscriptions.push(
1631+
vscode.commands.registerCommand('pr.closeRelatedEditors', closeAllPrAndReviewEditors)
1632+
);
16171633
}

0 commit comments

Comments
 (0)