Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/integrations/editor/DiffViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
}
}),
Expand All @@ -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}`)
}
}),
)
Expand Down
4 changes: 2 additions & 2 deletions src/integrations/editor/__tests__/DiffViewProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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() }
})
Expand Down