Skip to content

Commit e96d17e

Browse files
fix: fix replace diff preview clear cache
fix #442
1 parent 270214e commit e96d17e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/extension/preview.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ async function previewDiff(param: ChildToParent['previewDiff']) {
112112
doPreview(fileUri, param)
113113
}
114114

115+
function isMatchingPreviewUri(uri: Uri | undefined, previewUri: Uri) {
116+
return uri?.scheme === SCHEME && uri.path === previewUri.path
117+
}
118+
115119
async function doPreview(
116120
fileUri: Uri,
117121
{ filePath, locationsToSelect }: ChildToParent['previewDiff'],
@@ -121,6 +125,15 @@ async function doPreview(
121125
query: Date.now().toString(),
122126
})
123127
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+
}
124137
// https://github.com/microsoft/vscode/blob/d63202a5382aa104f5515ea09053a2a21a2587c6/src/vs/workbench/api/common/extHostApiCommands.ts#L422
125138
await commands.executeCommand(
126139
'vscode.diff',
@@ -129,10 +142,10 @@ async function doPreview(
129142
`${filename}${filename} (Replace Preview)`,
130143
{
131144
preserveFocus: true,
145+
revealIfVisible: true,
132146
},
133147
)
134-
const range = locationToRange(locationsToSelect)
135-
window.activeTextEditor?.revealRange(range, TextEditorRevealType.InCenter)
148+
activeEditor?.revealRange(range, TextEditorRevealType.InCenter)
136149
}
137150

138151
async function dismissDiff(param: ChildToParent['dismissDiff']) {

0 commit comments

Comments
 (0)