@@ -70,7 +70,11 @@ export class DiffViewProvider {
7070 // diff-open time. Opening the diff reuses the editor group's single preview
7171 // slot and evicts these tabs; we restore any that disappeared after the diff
7272 // session ends so the user's prior tab state is reconstructed.
73- private snapshotPreviewTabs : Array < { uri : vscode . Uri ; scrollLine : number | undefined ; viewColumn : vscode . ViewColumn } > = [ ]
73+ private snapshotPreviewTabs : Array < {
74+ uri : vscode . Uri
75+ scrollLine : number | undefined
76+ viewColumn : vscode . ViewColumn
77+ } > = [ ]
7478 private taskRef : WeakRef < Task >
7579
7680 constructor (
@@ -340,7 +344,18 @@ export class DiffViewProvider {
340344
341345 await this . closeAllDiffViews ( )
342346
343- await this . keepOrCloseEditedFile ( absolutePath , this . userTouchedDiffEditor )
347+ // Read auto-close preferences from state; fall back to defaults that
348+ // preserve the existing behavior when unset.
349+ const saveTask = this . taskRef . deref ( )
350+ const saveState = await saveTask ?. providerRef . deref ( ) ?. getState ( )
351+
352+ await this . keepOrCloseEditedFile (
353+ absolutePath ,
354+ this . userTouchedDiffEditor ,
355+ saveState ?. autoCloseZooOpenedFiles ?? true ,
356+ saveState ?. autoCloseZooOpenedFilesAfterUserEdited ?? false ,
357+ saveState ?. autoCloseZooOpenedNewFiles ?? false ,
358+ )
344359
345360 // Restore any preview tabs the diff evicted, reconstructing the user's
346361 // prior not-yet-edited tab state.
@@ -540,7 +555,18 @@ export class DiffViewProvider {
540555
541556 await this . closeAllDiffViews ( )
542557
543- await this . keepOrCloseEditedFile ( absolutePath )
558+ // Read auto-close preferences from state; fall back to defaults that
559+ // preserve the existing behavior when unset.
560+ const revertTask = this . taskRef . deref ( )
561+ const revertState = await revertTask ?. providerRef . deref ( ) ?. getState ( )
562+
563+ await this . keepOrCloseEditedFile (
564+ absolutePath ,
565+ false ,
566+ revertState ?. autoCloseZooOpenedFiles ?? true ,
567+ revertState ?. autoCloseZooOpenedFilesAfterUserEdited ?? false ,
568+ revertState ?. autoCloseZooOpenedNewFiles ?? false ,
569+ )
544570 }
545571
546572 // Restore any preview tabs the diff evicted, reconstructing the user's
@@ -608,16 +634,59 @@ export class DiffViewProvider {
608634 }
609635 }
610636
611- // Shared accept/deny cleanup: keep the edited file open if it was already open
612- // before the edit or the user interacted with it during the diff; otherwise
613- // close the tab that was opened transiently for the diff.
614- // Pass keepIfTouchedDiff=true (from saveChanges) to also keep the file when
615- // the user clicked or edited inside the diff editor itself.
616- private async keepOrCloseEditedFile ( absolutePath : string , keepIfTouchedDiff = false ) : Promise < void > {
617- if ( this . documentWasOpen || this . userTouchedDocument || keepIfTouchedDiff ) {
637+ // Shared accept/deny cleanup: applies the user's auto-close preferences to
638+ // decide whether to keep or close the edited file's tab after the diff settles.
639+ //
640+ // Decision table (evaluated in order; first match wins):
641+ // 1. File was already open before the edit -> always keep (closing it would
642+ // be destructive; user-opened tabs are never auto-closed).
643+ // 2. editType==="create" AND autoCloseZooOpenedNewFiles -> close the new file's tab.
644+ // 3. userTouchedDocument OR keepIfTouchedDiff -> the "keep if touched" guard
645+ // applies; it is overridden (close) only when BOTH autoCloseZooOpenedFiles
646+ // and autoCloseZooOpenedFilesAfterUserEdited are enabled. The override is a
647+ // refinement of the base auto-close, so it has no effect when the base
648+ // setting is off.
649+ // 4. autoCloseZooOpenedFiles=false -> keep the transiently-opened tab.
650+ // 5. Default -> close the transiently-opened tab (current behavior preserved).
651+ //
652+ // keepIfTouchedDiff is passed as true from saveChanges() when the user clicked
653+ // or typed inside the diff editor itself.
654+ private async keepOrCloseEditedFile (
655+ absolutePath : string ,
656+ keepIfTouchedDiff = false ,
657+ autoCloseZooOpenedFiles = true ,
658+ autoCloseZooOpenedFilesAfterUserEdited = false ,
659+ autoCloseZooOpenedNewFiles = false ,
660+ ) : Promise < void > {
661+ // Files the user already had open are never auto-closed.
662+ if ( this . documentWasOpen ) {
618663 await this . showEditedFileWithoutDisruptingFocus ( absolutePath )
619- } else {
664+ return
665+ }
666+
667+ // New files on the accept path: close when autoCloseZooOpenedNewFiles is enabled.
668+ if ( this . editType === "create" && autoCloseZooOpenedNewFiles ) {
620669 await this . closeFileTab ( absolutePath )
670+ return
671+ }
672+
673+ const userInteracted = this . userTouchedDocument || keepIfTouchedDiff
674+ if ( userInteracted ) {
675+ // Override the "keep if touched" guard only when the base auto-close is
676+ // also enabled; the override is a refinement, not an independent toggle.
677+ if ( autoCloseZooOpenedFiles && autoCloseZooOpenedFilesAfterUserEdited ) {
678+ await this . closeFileTab ( absolutePath )
679+ } else {
680+ await this . showEditedFileWithoutDisruptingFocus ( absolutePath )
681+ }
682+ return
683+ }
684+
685+ // Transient tab opened by Zoo: close by default, keep only when opted out.
686+ if ( autoCloseZooOpenedFiles ) {
687+ await this . closeFileTab ( absolutePath )
688+ } else {
689+ await this . showEditedFileWithoutDisruptingFocus ( absolutePath )
621690 }
622691 }
623692
@@ -708,7 +777,11 @@ export class DiffViewProvider {
708777 const visibleEditor = vscode . window . visibleTextEditors . find (
709778 ( e ) => e . document . uri . scheme === "file" && arePathsEqual ( e . document . uri . fsPath , uri . fsPath ) ,
710779 )
711- return { uri, scrollLine : visibleEditor ?. visibleRanges ?. [ 0 ] ?. start . line , viewColumn : group . viewColumn }
780+ return {
781+ uri,
782+ scrollLine : visibleEditor ?. visibleRanges ?. [ 0 ] ?. start . line ,
783+ viewColumn : group . viewColumn ,
784+ }
712785 } ) ,
713786 )
714787 }
@@ -999,10 +1072,7 @@ export class DiffViewProvider {
9991072 editor . selection = new vscode . Selection ( targetPosition , targetPosition )
10001073
10011074 const lineLength = editor . document . lineAt ? editor . document . lineAt ( safeLine ) . text . length : 0
1002- editor . revealRange (
1003- new vscode . Range ( safeLine , 0 , safeLine , lineLength ) ,
1004- vscode . TextEditorRevealType . InCenter ,
1005- )
1075+ editor . revealRange ( new vscode . Range ( safeLine , 0 , safeLine , lineLength ) , vscode . TextEditorRevealType . InCenter )
10061076 }
10071077
10081078 private stripAllBOMs ( input : string ) : string {
0 commit comments