mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-06 02:47:56 +00:00
fix(editor): prevent file editing issues when git diff views are open (#8676)
* 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. * Remove the warnings * fix(editor): enforce file:// scheme in editor lookups to prevent git diff issues --------- Co-authored-by: daniel-lxs <ricciodaniel98@gmail.com>
This commit is contained in:
parent
1a3a873002
commit
270dce5050
2 changed files with 17 additions and 9 deletions
|
|
@ -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) {
|
||||
|
|
@ -509,13 +512,14 @@ 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) {
|
||||
|
|
@ -529,7 +533,11 @@ 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)
|
||||
|
|
|
|||
|
|
@ -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() }
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue