Skip to content

Commit 547874e

Browse files
authored
Revert "Fix: Preserve editor state and prevent tab unpinning during diffs" (#2956)
Revert "Fix: Preserve editor state and prevent tab unpinning during diffs (#2…" This reverts commit c2dd743.
1 parent 06db547 commit 547874e

File tree

1 file changed

+9
-60
lines changed

1 file changed

+9
-60
lines changed

src/integrations/editor/DiffViewProvider.ts

Lines changed: 9 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ 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
2120
private relPath?: string
2221
private newContent?: string
2322
private activeDiffEditor?: vscode.TextEditor
@@ -66,22 +65,11 @@ export class DiffViewProvider {
6665
.filter(
6766
(tab) => tab.input instanceof vscode.TabInputText && arePathsEqual(tab.input.uri.fsPath, absolutePath),
6867
)
69-
// Check if the document is already open and store its state
70-
// DO NOT close the original tab to preserve pin status
7168
for (const tab of tabs) {
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
69+
if (!tab.isDirty) {
70+
await vscode.window.tabGroups.close(tab)
8471
}
72+
this.documentWasOpen = true
8573
}
8674
this.activeDiffEditor = await this.openDiffEditor()
8775
this.fadedOverlayController = new DecorationController("fadedOverlay", this.activeDiffEditor)
@@ -168,31 +156,9 @@ export class DiffViewProvider {
168156
await updatedDocument.save()
169157
}
170158

171-
// Close the diff view first
159+
await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), { preview: false })
172160
await this.closeAllDiffViews()
173161

174-
// If the original document was open, try to focus it.
175-
// 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-
}
195-
196162
/*
197163
Getting diagnostics before and after the file edit is a better approach than
198164
automatically tracking problems in real-time. This method ensures we only
@@ -271,28 +237,12 @@ export class DiffViewProvider {
271237
await vscode.workspace.applyEdit(edit)
272238
await updatedDocument.save()
273239
console.log(`File ${absolutePath} has been reverted to its original content.`)
274-
// Close the diff view first
275-
await this.closeAllDiffViews()
276-
277-
// If the document was originally open, ensure it's focused.
278-
// 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-
}
240+
if (this.documentWasOpen) {
241+
await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), {
242+
preview: false,
243+
})
295244
}
245+
await this.closeAllDiffViews()
296246
}
297247

298248
// edit is done
@@ -408,7 +358,6 @@ export class DiffViewProvider {
408358
this.originalContent = undefined
409359
this.createdDirs = []
410360
this.documentWasOpen = false
411-
this.originalViewColumn = undefined // Reset stored view column
412361
this.activeDiffEditor = undefined
413362
this.fadedOverlayController = undefined
414363
this.activeLineController = undefined

0 commit comments

Comments
 (0)