@@ -17,7 +17,6 @@ export class DiffViewProvider {
17
17
originalContent : string | undefined
18
18
private createdDirs : string [ ] = [ ]
19
19
private documentWasOpen = false
20
- private originalViewColumn ?: vscode . ViewColumn // Store the original view column
21
20
private relPath ?: string
22
21
private newContent ?: string
23
22
private activeDiffEditor ?: vscode . TextEditor
@@ -66,22 +65,11 @@ export class DiffViewProvider {
66
65
. filter (
67
66
( tab ) => tab . input instanceof vscode . TabInputText && arePathsEqual ( tab . input . uri . fsPath , absolutePath ) ,
68
67
)
69
- // Check if the document is already open and store its state
70
- // DO NOT close the original tab to preserve pin status
71
68
for ( const tab of tabs ) {
72
- if ( tab . input instanceof vscode . TabInputText && arePathsEqual ( tab . input . uri . fsPath , absolutePath ) ) {
73
- this . originalViewColumn = tab . group . viewColumn
74
- this . documentWasOpen = true
75
- // Ensure the tab is not dirty before proceeding, but don't close it
76
- if ( tab . isDirty ) {
77
- // Find the document associated with the tab and save it
78
- const doc = vscode . workspace . textDocuments . find ( ( d ) => arePathsEqual ( d . uri . fsPath , absolutePath ) )
79
- if ( doc ) {
80
- await doc . save ( )
81
- }
82
- }
83
- break // Found the relevant tab, no need to check others
69
+ if ( ! tab . isDirty ) {
70
+ await vscode . window . tabGroups . close ( tab )
84
71
}
72
+ this . documentWasOpen = true
85
73
}
86
74
this . activeDiffEditor = await this . openDiffEditor ( )
87
75
this . fadedOverlayController = new DecorationController ( "fadedOverlay" , this . activeDiffEditor )
@@ -168,31 +156,9 @@ export class DiffViewProvider {
168
156
await updatedDocument . save ( )
169
157
}
170
158
171
- // Close the diff view first
159
+ await vscode . window . showTextDocument ( vscode . Uri . file ( absolutePath ) , { preview : false } )
172
160
await this . closeAllDiffViews ( )
173
161
174
- // If the original document was open, try to focus it.
175
- // VS Code should handle showing the updated content automatically since the file was saved.
176
- if ( this . documentWasOpen && this . originalViewColumn ) {
177
- // Find the editor for the original document and reveal it
178
- const originalEditor = vscode . window . visibleTextEditors . find (
179
- ( editor ) =>
180
- arePathsEqual ( editor . document . uri . fsPath , absolutePath ) &&
181
- editor . viewColumn === this . originalViewColumn ,
182
- )
183
- if ( originalEditor ) {
184
- // Reveal a range (e.g., the start) to ensure focus
185
- const position = new vscode . Position ( 0 , 0 )
186
- originalEditor . revealRange ( new vscode . Range ( position , position ) , vscode . TextEditorRevealType . AtTop )
187
- } else {
188
- // Fallback if editor not found (shouldn't happen often if documentWasOpen is true)
189
- await vscode . window . showTextDocument ( vscode . Uri . file ( absolutePath ) , {
190
- preview : false ,
191
- viewColumn : this . originalViewColumn ,
192
- } )
193
- }
194
- }
195
-
196
162
/*
197
163
Getting diagnostics before and after the file edit is a better approach than
198
164
automatically tracking problems in real-time. This method ensures we only
@@ -271,28 +237,12 @@ export class DiffViewProvider {
271
237
await vscode . workspace . applyEdit ( edit )
272
238
await updatedDocument . save ( )
273
239
console . log ( `File ${ absolutePath } has been reverted to its original content.` )
274
- // Close the diff view first
275
- await this . closeAllDiffViews ( )
276
-
277
- // If the document was originally open, ensure it's focused.
278
- // The revert logic already applied the original content and saved.
279
- if ( this . documentWasOpen && this . originalViewColumn ) {
280
- const originalEditor = vscode . window . visibleTextEditors . find (
281
- ( editor ) =>
282
- arePathsEqual ( editor . document . uri . fsPath , absolutePath ) &&
283
- editor . viewColumn === this . originalViewColumn ,
284
- )
285
- if ( originalEditor ) {
286
- const position = new vscode . Position ( 0 , 0 )
287
- originalEditor . revealRange ( new vscode . Range ( position , position ) , vscode . TextEditorRevealType . AtTop )
288
- } else {
289
- // Fallback
290
- await vscode . window . showTextDocument ( vscode . Uri . file ( absolutePath ) , {
291
- preview : false ,
292
- viewColumn : this . originalViewColumn ,
293
- } )
294
- }
240
+ if ( this . documentWasOpen ) {
241
+ await vscode . window . showTextDocument ( vscode . Uri . file ( absolutePath ) , {
242
+ preview : false ,
243
+ } )
295
244
}
245
+ await this . closeAllDiffViews ( )
296
246
}
297
247
298
248
// edit is done
@@ -408,7 +358,6 @@ export class DiffViewProvider {
408
358
this . originalContent = undefined
409
359
this . createdDirs = [ ]
410
360
this . documentWasOpen = false
411
- this . originalViewColumn = undefined // Reset stored view column
412
361
this . activeDiffEditor = undefined
413
362
this . fadedOverlayController = undefined
414
363
this . activeLineController = undefined
0 commit comments