Skip to content

Commit b16d87b

Browse files
authored
Update DiffViewProvider.ts
1 parent 6e01e05 commit b16d87b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/integrations/editor/DiffViewProvider.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class DiffViewProvider {
1717
originalContent: string | undefined
1818
private createdDirs: string[] = []
1919
private documentWasOpen = false
20+
private originalViewColumn?: vscode.ViewColumn // Store the original view column
2021
private relPath?: string
2122
private newContent?: string
2223
private activeDiffEditor?: vscode.TextEditor
@@ -65,11 +66,22 @@ export class DiffViewProvider {
6566
.filter(
6667
(tab) => tab.input instanceof vscode.TabInputText && arePathsEqual(tab.input.uri.fsPath, absolutePath),
6768
)
69+
// Check if the document is already open and store its state
70+
// DO NOT close the original tab to preserve pin status
6871
for (const tab of tabs) {
69-
if (!tab.isDirty) {
70-
await vscode.window.tabGroups.close(tab)
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
7184
}
72-
this.documentWasOpen = true
7385
}
7486
this.activeDiffEditor = await this.openDiffEditor()
7587
this.fadedOverlayController = new DecorationController("fadedOverlay", this.activeDiffEditor)
@@ -385,6 +397,7 @@ export class DiffViewProvider {
385397
this.originalContent = undefined
386398
this.createdDirs = []
387399
this.documentWasOpen = false
400+
this.originalViewColumn = undefined // Reset stored view column
388401
this.activeDiffEditor = undefined
389402
this.fadedOverlayController = undefined
390403
this.activeLineController = undefined

0 commit comments

Comments
 (0)