@@ -207,7 +207,15 @@ export class DiffViewProvider {
207207 await updatedDocument . save ( )
208208 }
209209
210- await vscode . window . showTextDocument ( vscode . Uri . file ( absolutePath ) , { preview : false , preserveFocus : true } )
210+ // Check if the file is already the active editor to avoid viewport jump
211+ const activeEditor = vscode . window . activeTextEditor
212+ const isAlreadyActive = activeEditor && arePathsEqual ( activeEditor . document . uri . fsPath , absolutePath )
213+
214+ if ( ! isAlreadyActive ) {
215+ // Only show the document if it's not already the active editor
216+ await vscode . window . showTextDocument ( vscode . Uri . file ( absolutePath ) , { preview : false , preserveFocus : true } )
217+ }
218+
211219 await this . closeAllDiffViews ( )
212220
213221 // Getting diagnostics before and after the file edit is a better approach than
@@ -405,10 +413,17 @@ export class DiffViewProvider {
405413 await updatedDocument . save ( )
406414
407415 if ( this . documentWasOpen ) {
408- await vscode . window . showTextDocument ( vscode . Uri . file ( absolutePath ) , {
409- preview : false ,
410- preserveFocus : true ,
411- } )
416+ // Check if the file is already the active editor to avoid viewport jump
417+ const activeEditor = vscode . window . activeTextEditor
418+ const isAlreadyActive = activeEditor && arePathsEqual ( activeEditor . document . uri . fsPath , absolutePath )
419+
420+ if ( ! isAlreadyActive ) {
421+ // Only show the document if it's not already the active editor
422+ await vscode . window . showTextDocument ( vscode . Uri . file ( absolutePath ) , {
423+ preview : false ,
424+ preserveFocus : true ,
425+ } )
426+ }
412427 }
413428
414429 await this . closeAllDiffViews ( )
@@ -661,11 +676,17 @@ export class DiffViewProvider {
661676 // Open the document to ensure diagnostics are loaded
662677 // When openFile is false (PREVENT_FOCUS_DISRUPTION enabled), we only open in memory
663678 if ( openFile ) {
664- // Show the document in the editor
665- await vscode . window . showTextDocument ( vscode . Uri . file ( absolutePath ) , {
666- preview : false ,
667- preserveFocus : true ,
668- } )
679+ // Check if the file is already the active editor to avoid viewport jump
680+ const activeEditor = vscode . window . activeTextEditor
681+ const isAlreadyActive = activeEditor && arePathsEqual ( activeEditor . document . uri . fsPath , absolutePath )
682+
683+ if ( ! isAlreadyActive ) {
684+ // Only show the document if it's not already the active editor
685+ await vscode . window . showTextDocument ( vscode . Uri . file ( absolutePath ) , {
686+ preview : false ,
687+ preserveFocus : true ,
688+ } )
689+ }
669690 } else {
670691 // Just open the document in memory to trigger diagnostics without showing it
671692 const doc = await vscode . workspace . openTextDocument ( vscode . Uri . file ( absolutePath ) )
0 commit comments