|
1 | 1 | import * as vscode from "vscode" |
| 2 | +import { TextDocumentShowOptions, ViewColumn } from "vscode" |
2 | 3 | import * as path from "path" |
3 | 4 | import * as fs from "fs/promises" |
4 | 5 | import * as diff from "diff" |
@@ -121,11 +122,6 @@ export class DiffViewProvider { |
121 | 122 | throw new Error("User closed text editor, unable to edit file...") |
122 | 123 | } |
123 | 124 |
|
124 | | - // Place cursor at the beginning of the diff editor to keep it out of |
125 | | - // the way of the stream animation, but do this without stealing focus |
126 | | - const beginningOfDocument = new vscode.Position(0, 0) |
127 | | - diffEditor.selection = new vscode.Selection(beginningOfDocument, beginningOfDocument) |
128 | | - |
129 | 125 | const endLine = accumulatedLines.length |
130 | 126 | // Replace all content up to the current line with accumulated lines. |
131 | 127 | const edit = new vscode.WorkspaceEdit() |
@@ -188,15 +184,13 @@ export class DiffViewProvider { |
188 | 184 | return { newProblemsMessage: undefined, userEdits: undefined, finalContent: undefined } |
189 | 185 | } |
190 | 186 |
|
191 | | - const absolutePath = path.resolve(this.cwd, this.relPath) |
192 | 187 | const updatedDocument = this.activeDiffEditor.document |
193 | 188 | const editedContent = updatedDocument.getText() |
194 | 189 |
|
195 | 190 | if (updatedDocument.isDirty) { |
196 | 191 | await updatedDocument.save() |
197 | 192 | } |
198 | 193 |
|
199 | | - await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), { preview: false, preserveFocus: true }) |
200 | 194 | await this.closeAllDiffViews() |
201 | 195 |
|
202 | 196 | // Getting diagnostics before and after the file edit is a better approach than |
@@ -500,23 +494,22 @@ export class DiffViewProvider { |
500 | 494 | } |
501 | 495 | }), |
502 | 496 | ) |
503 | | - |
504 | | - // Pre-open the file as a text document to ensure it doesn't open in preview mode |
505 | | - // This fixes issues with files that have custom editor associations (like markdown preview) |
506 | | - vscode.window |
507 | | - .showTextDocument(uri, { preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true }) |
508 | | - .then(() => { |
509 | | - // Execute the diff command after ensuring the file is open as text |
510 | | - return vscode.commands.executeCommand( |
511 | | - "vscode.diff", |
512 | | - vscode.Uri.parse(`${DIFF_VIEW_URI_SCHEME}:${fileName}`).with({ |
513 | | - query: Buffer.from(this.originalContent ?? "").toString("base64"), |
514 | | - }), |
515 | | - uri, |
516 | | - `${fileName}: ${fileExists ? `${DIFF_VIEW_LABEL_CHANGES}` : "New File"} (Editable)`, |
517 | | - { preserveFocus: true }, |
518 | | - ) |
519 | | - }) |
| 497 | + // Now execute the diff command |
| 498 | + const textShowOptions: TextDocumentShowOptions = { |
| 499 | + preview: false, |
| 500 | + viewColumn: ViewColumn.Beside, |
| 501 | + preserveFocus: true, |
| 502 | + } |
| 503 | + vscode.commands |
| 504 | + .executeCommand( |
| 505 | + "vscode.diff", |
| 506 | + vscode.Uri.parse(`${DIFF_VIEW_URI_SCHEME}:${fileName}`).with({ |
| 507 | + query: Buffer.from(this.originalContent ?? "").toString("base64"), |
| 508 | + }), |
| 509 | + uri, |
| 510 | + `${fileName}: ${fileExists ? `${DIFF_VIEW_LABEL_CHANGES}` : "New File"} (Editable)`, |
| 511 | + textShowOptions, |
| 512 | + ) |
520 | 513 | .then( |
521 | 514 | () => { |
522 | 515 | // Command executed successfully, now wait for the editor to appear |
|
0 commit comments