@@ -173,25 +173,8 @@ export class DiffViewProvider {
173173
174174 // If the original document was open, try to focus it.
175175 // 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- }
176+ // If the original document was open, try to focus it.
177+ await this . _focusOriginalDocument ( absolutePath , this . originalViewColumn )
195178
196179 /*
197180 Getting diagnostics before and after the file edit is a better approach than
@@ -276,23 +259,8 @@ export class DiffViewProvider {
276259
277260 // If the document was originally open, ensure it's focused.
278261 // 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- }
295- }
262+ // If the document was originally open, ensure it's focused.
263+ await this . _focusOriginalDocument ( absolutePath , this . originalViewColumn )
296264 }
297265
298266 // edit is done
@@ -401,6 +369,29 @@ export class DiffViewProvider {
401369 return result
402370 }
403371
372+ private async _focusOriginalDocument (
373+ absolutePath : string ,
374+ viewColumn : vscode . ViewColumn | undefined ,
375+ ) : Promise < void > {
376+ if ( this . documentWasOpen && viewColumn ) {
377+ // Find the editor for the original document and reveal it
378+ const originalEditor = vscode . window . visibleTextEditors . find (
379+ ( editor ) => arePathsEqual ( editor . document . uri . fsPath , absolutePath ) && editor . viewColumn === viewColumn ,
380+ )
381+ if ( originalEditor ) {
382+ // Reveal a range (e.g., the start) to ensure focus
383+ const position = new vscode . Position ( 0 , 0 )
384+ originalEditor . revealRange ( new vscode . Range ( position , position ) , vscode . TextEditorRevealType . AtTop )
385+ } else {
386+ // Fallback if editor not found
387+ await vscode . window . showTextDocument ( vscode . Uri . file ( absolutePath ) , {
388+ preview : false ,
389+ viewColumn : viewColumn ,
390+ } )
391+ }
392+ }
393+ }
394+
404395 // close editor if open?
405396 async reset ( ) {
406397 this . editType = undefined
0 commit comments