From 6cec1f39c9292cce518e508948e0584661122c08 Mon Sep 17 00:00:00 2001 From: Chris Hasson Date: Wed, 15 Oct 2025 17:23:33 -0700 Subject: [PATCH 1/3] fix(editor): prevent file editing issues when git diff views are open Add scheme checks to ensure only file:// URIs are matched when finding editors, avoiding issues with git diffs and other schemes. Includes error logging for failed editor lookups. --- src/integrations/editor/DiffViewProvider.ts | 17 +++++++++++++---- .../editor/__tests__/DiffViewProvider.spec.ts | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/integrations/editor/DiffViewProvider.ts b/src/integrations/editor/DiffViewProvider.ts index 5acf09ea789..69a4a0f3035 100644 --- a/src/integrations/editor/DiffViewProvider.ts +++ b/src/integrations/editor/DiffViewProvider.ts @@ -509,18 +509,21 @@ export class DiffViewProvider { // Listen for document open events - more efficient than scanning all tabs disposables.push( vscode.workspace.onDidOpenTextDocument(async (document) => { - if (arePathsEqual(document.uri.fsPath, uri.fsPath)) { + // Only match file:// scheme documents to avoid git diffs + if (document.uri.scheme === "file" && arePathsEqual(document.uri.fsPath, uri.fsPath)) { // Wait a tick for the editor to be available await new Promise((r) => setTimeout(r, 0)) // Find the editor for this document - const editor = vscode.window.visibleTextEditors.find((e) => - arePathsEqual(e.document.uri.fsPath, uri.fsPath), + const editor = vscode.window.visibleTextEditors.find( + (e) => e.document.uri.scheme === "file" && arePathsEqual(e.document.uri.fsPath, uri.fsPath), ) if (editor) { cleanup() resolve(editor) + } else { + console.error(`[DiffViewProvider] Failed to find valid editor for ${fileName}`) } } }), @@ -529,10 +532,16 @@ export class DiffViewProvider { // Also listen for visible editor changes as a fallback disposables.push( vscode.window.onDidChangeVisibleTextEditors((editors) => { - const editor = editors.find((e) => arePathsEqual(e.document.uri.fsPath, uri.fsPath)) + const editor = editors.find((e) => { + const isFileScheme = e.document.uri.scheme === "file" + const pathMatches = arePathsEqual(e.document.uri.fsPath, uri.fsPath) + return isFileScheme && pathMatches + }) if (editor) { cleanup() resolve(editor) + } else { + console.error(`[DiffViewProvider] Failed to find valid editor for ${fileName}`) } }), ) diff --git a/src/integrations/editor/__tests__/DiffViewProvider.spec.ts b/src/integrations/editor/__tests__/DiffViewProvider.spec.ts index 0737b143cda..e99f7bf9c86 100644 --- a/src/integrations/editor/__tests__/DiffViewProvider.spec.ts +++ b/src/integrations/editor/__tests__/DiffViewProvider.spec.ts @@ -187,7 +187,7 @@ describe("DiffViewProvider", () => { // Setup const mockEditor = { document: { - uri: { fsPath: `${mockCwd}/test.md` }, + uri: { fsPath: `${mockCwd}/test.md`, scheme: "file" }, getText: vi.fn().mockReturnValue(""), lineCount: 0, }, @@ -220,7 +220,7 @@ describe("DiffViewProvider", () => { vi.mocked(vscode.workspace.onDidOpenTextDocument).mockImplementation((callback) => { // Trigger the callback immediately with the document setTimeout(() => { - callback({ uri: { fsPath: `${mockCwd}/test.md` } } as any) + callback({ uri: { fsPath: `${mockCwd}/test.md`, scheme: "file" } } as any) }, 0) return { dispose: vi.fn() } }) From 4a107b7117b8130182dc36453e29c1c3e19436a6 Mon Sep 17 00:00:00 2001 From: Chris Hasson Date: Wed, 15 Oct 2025 17:52:33 -0700 Subject: [PATCH 2/3] Remove the warnings --- src/integrations/editor/DiffViewProvider.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/integrations/editor/DiffViewProvider.ts b/src/integrations/editor/DiffViewProvider.ts index 69a4a0f3035..8dca20060ff 100644 --- a/src/integrations/editor/DiffViewProvider.ts +++ b/src/integrations/editor/DiffViewProvider.ts @@ -522,8 +522,6 @@ export class DiffViewProvider { if (editor) { cleanup() resolve(editor) - } else { - console.error(`[DiffViewProvider] Failed to find valid editor for ${fileName}`) } } }), @@ -540,8 +538,6 @@ export class DiffViewProvider { if (editor) { cleanup() resolve(editor) - } else { - console.error(`[DiffViewProvider] Failed to find valid editor for ${fileName}`) } }), ) From 6feb3e53fe1b9445a2e7cd726dae6f92fdf584bc Mon Sep 17 00:00:00 2001 From: daniel-lxs Date: Wed, 15 Oct 2025 19:55:29 -0500 Subject: [PATCH 3/3] fix(editor): enforce file:// scheme in editor lookups to prevent git diff issues --- src/integrations/editor/DiffViewProvider.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/integrations/editor/DiffViewProvider.ts b/src/integrations/editor/DiffViewProvider.ts index 8dca20060ff..d42eba082cb 100644 --- a/src/integrations/editor/DiffViewProvider.ts +++ b/src/integrations/editor/DiffViewProvider.ts @@ -54,8 +54,8 @@ export class DiffViewProvider { // If the file is already open, ensure it's not dirty before getting its // contents. if (fileExists) { - const existingDocument = vscode.workspace.textDocuments.find((doc) => - arePathsEqual(doc.uri.fsPath, absolutePath), + const existingDocument = vscode.workspace.textDocuments.find( + (doc) => doc.uri.scheme === "file" && arePathsEqual(doc.uri.fsPath, absolutePath), ) if (existingDocument && existingDocument.isDirty) { @@ -91,7 +91,10 @@ export class DiffViewProvider { .map((tg) => tg.tabs) .flat() .filter( - (tab) => tab.input instanceof vscode.TabInputText && arePathsEqual(tab.input.uri.fsPath, absolutePath), + (tab) => + tab.input instanceof vscode.TabInputText && + tab.input.uri.scheme === "file" && + arePathsEqual(tab.input.uri.fsPath, absolutePath), ) for (const tab of tabs) {