@@ -112,6 +112,10 @@ async function previewDiff(param: ChildToParent['previewDiff']) {
112
112
doPreview ( fileUri , param )
113
113
}
114
114
115
+ function isMatchingPreviewUri ( uri : Uri | undefined , previewUri : Uri ) {
116
+ return uri ?. scheme === SCHEME && uri . path === previewUri . path
117
+ }
118
+
115
119
async function doPreview (
116
120
fileUri : Uri ,
117
121
{ filePath, locationsToSelect } : ChildToParent [ 'previewDiff' ] ,
@@ -121,6 +125,15 @@ async function doPreview(
121
125
query : Date . now ( ) . toString ( ) ,
122
126
} )
123
127
const filename = path . basename ( filePath )
128
+ const range = locationToRange ( locationsToSelect )
129
+ const activeEditor = window . activeTextEditor
130
+ // if the preview is already open, reveal it directly
131
+ // calling diff again will close the previous window
132
+ // and delete entry previewContents
133
+ if ( isMatchingPreviewUri ( activeEditor ?. document . uri , previewUri ) ) {
134
+ activeEditor ?. revealRange ( range , TextEditorRevealType . InCenter )
135
+ return
136
+ }
124
137
// https://github.com/microsoft/vscode/blob/d63202a5382aa104f5515ea09053a2a21a2587c6/src/vs/workbench/api/common/extHostApiCommands.ts#L422
125
138
await commands . executeCommand (
126
139
'vscode.diff' ,
@@ -129,10 +142,10 @@ async function doPreview(
129
142
`${ filename } ↔ ${ filename } (Replace Preview)` ,
130
143
{
131
144
preserveFocus : true ,
145
+ revealIfVisible : true ,
132
146
} ,
133
147
)
134
- const range = locationToRange ( locationsToSelect )
135
- window . activeTextEditor ?. revealRange ( range , TextEditorRevealType . InCenter )
148
+ activeEditor ?. revealRange ( range , TextEditorRevealType . InCenter )
136
149
}
137
150
138
151
async function dismissDiff ( param : ChildToParent [ 'dismissDiff' ] ) {
0 commit comments