Skip to content

Commit fedddae

Browse files
committed
feat(diffView): add autoCloseTabs setting to manage tab closure behavior
1 parent 1d2c965 commit fedddae

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/integrations/editor/DiffViewProvider.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class DiffViewProvider {
2929
private rooOpenedTabs: Set<string> = new Set()
3030
private preserveFocus: boolean = false
3131
private autoFocus: boolean = true
32+
private autoCloseTabs: boolean = false
3233
// have to set the default view column to -1 since we need to set it in the initialize method and during initialization the enum ViewColumn is undefined
3334
private viewColumn: ViewColumn = -1 // ViewColumn.Active
3435

@@ -37,6 +38,7 @@ export class DiffViewProvider {
3738
async initialize(viewColumn: ViewColumn) {
3839
const provider = ClineProvider.getVisibleInstance()
3940
const autoFocus = vscode.workspace.getConfiguration("roo-cline").get<boolean>("diffViewAutoFocus", true)
41+
4042
const autoApproval =
4143
(provider?.getValue("autoApprovalEnabled") && provider?.getValue("alwaysAllowWrite")) ?? false
4244
// If autoApproval is enabled, we want to preserve focus if autoFocus is disabled
@@ -45,6 +47,7 @@ export class DiffViewProvider {
4547
// If autoFocus is disabled, we want to preserve focus on the diff editor we are working on.
4648
this.preserveFocus = autoApproval && !autoFocus
4749
this.autoFocus = autoFocus
50+
this.autoCloseTabs = vscode.workspace.getConfiguration("roo-cline").get<boolean>("autoCloseRooTabs", false)
4851
this.viewColumn = viewColumn
4952
// Track currently visible editors and active editor for focus restoration and tab cleanup
5053
this.rooOpenedTabs.clear()
@@ -102,10 +105,6 @@ export class DiffViewProvider {
102105
this.documentWasOpen = true
103106
}
104107
this.activeDiffEditor = await this.openDiffEditor()
105-
// Track the diff editor tab as opened by Roo
106-
if (this.activeDiffEditor) {
107-
this.rooOpenedTabs.add(this.activeDiffEditor.document.uri.toString())
108-
}
109108
this.fadedOverlayController = new DecorationController("fadedOverlay", this.activeDiffEditor)
110109
this.activeLineController = new DecorationController("activeLine", this.activeDiffEditor)
111110
// Apply faded overlay to all lines initially
@@ -118,9 +117,8 @@ export class DiffViewProvider {
118117
* Opens a file editor and tracks it as opened by Roo if not already open.
119118
*/
120119
private async showAndTrackEditor(uri: vscode.Uri, options: vscode.TextDocumentShowOptions = {}) {
121-
const alreadyOpen = vscode.window.visibleTextEditors.some((ed) => ed.document.uri.toString() === uri.toString())
122120
const editor = await vscode.window.showTextDocument(uri, options)
123-
if (!alreadyOpen) {
121+
if (this.autoCloseTabs && !this.documentWasOpen) {
124122
this.rooOpenedTabs.add(uri.toString())
125123
}
126124
return editor
@@ -307,16 +305,14 @@ export class DiffViewProvider {
307305
}
308306

309307
private async closeAllRooOpenedViews() {
310-
const autoCloseTabs = vscode.workspace.getConfiguration("roo-cline").get<boolean>("autoCloseRooTabs", false)
311-
312308
const tabs = vscode.window.tabGroups.all
313309
.flatMap((tg) => tg.tabs)
314310
.filter(
315311
(tab) =>
316312
(tab.input instanceof vscode.TabInputTextDiff &&
317313
tab.input?.original?.scheme === DIFF_VIEW_URI_SCHEME) ||
318314
// close if in rooOpenedTabs and autoCloseTabs is enabled
319-
(autoCloseTabs &&
315+
(this.autoCloseTabs &&
320316
tab.input instanceof vscode.TabInputText &&
321317
this.rooOpenedTabs.has(tab.input.uri.toString())),
322318
)
@@ -393,8 +389,10 @@ export class DiffViewProvider {
393389
vscode.commands
394390
.executeCommand("vscode.diff", leftUri, rightUri, title, textDocumentShowOptions)
395391
.then(() => {
396-
// Track the diff tab as opened by Roo
397-
this.rooOpenedTabs.add(rightUri.toString())
392+
if (this.autoCloseTabs && !this.documentWasOpen) {
393+
// If the diff tab is not already open, add it to the set
394+
this.rooOpenedTabs.add(rightUri.toString())
395+
}
398396
// If autoFocus is true, we don't need to do anything
399397
if (this.autoFocus) {
400398
return

0 commit comments

Comments
 (0)