Skip to content

Commit c9335a7

Browse files
committed
refactor: extract diff view label separator as shared constant
- Add DIFF_VIEW_LABEL_SEPARATOR constant to prevent breaking logic if string changes - Update all usages in DiffViewProvider.ts and test file - Addresses PR review feedback for better maintainability
1 parent 1aae27f commit c9335a7

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/integrations/editor/DiffViewProvider.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Task } from "../../core/task/Task"
1515
import { DecorationController } from "./DecorationController"
1616

1717
export const DIFF_VIEW_URI_SCHEME = "cline-diff"
18+
export const DIFF_VIEW_LABEL_SEPARATOR = "↔ Roo's Changes"
1819

1920
// TODO: https://github.com/cline/cline/pull/3354
2021
export class DiffViewProvider {
@@ -397,7 +398,7 @@ export class DiffViewProvider {
397398
// Also check by tab label for our specific diff views
398399
// This catches cases where the diff view might be created differently
399400
// when files are pre-opened as text documents
400-
if (tab.label.includes("↔ Roo's Changes") && !tab.isDirty) {
401+
if (tab.label.includes(DIFF_VIEW_LABEL_SEPARATOR) && !tab.isDirty) {
401402
return true
402403
}
403404

@@ -512,7 +513,7 @@ export class DiffViewProvider {
512513
query: Buffer.from(this.originalContent ?? "").toString("base64"),
513514
}),
514515
uri,
515-
`${fileName}: ${fileExists ? "Original ↔ Roo's Changes" : "New File"} (Editable)`,
516+
`${fileName}: ${fileExists ? `Original ${DIFF_VIEW_LABEL_SEPARATOR}` : "New File"} (Editable)`,
516517
{ preserveFocus: true },
517518
)
518519
})

src/integrations/editor/__tests__/DiffViewProvider.spec.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DiffViewProvider, DIFF_VIEW_URI_SCHEME } from "../DiffViewProvider"
1+
import { DiffViewProvider, DIFF_VIEW_URI_SCHEME, DIFF_VIEW_LABEL_SEPARATOR } from "../DiffViewProvider"
22
import * as vscode from "vscode"
33
import * as path from "path"
44

@@ -219,7 +219,7 @@ describe("DiffViewProvider", () => {
219219
"vscode.diff",
220220
expect.any(Object),
221221
expect.any(Object),
222-
"test.md: Original ↔ Roo's Changes (Editable)",
222+
`test.md: Original ${DIFF_VIEW_LABEL_SEPARATOR} (Editable)`,
223223
{ preserveFocus: true },
224224
)
225225
})
@@ -255,7 +255,7 @@ describe("DiffViewProvider", () => {
255255
original: { scheme: DIFF_VIEW_URI_SCHEME },
256256
modified: { fsPath: "/test/file1.ts" },
257257
},
258-
label: "file1.ts: Original ↔ Roo's Changes (Editable)",
258+
label: `file1.ts: Original ${DIFF_VIEW_LABEL_SEPARATOR} (Editable)`,
259259
isDirty: false,
260260
},
261261
// Diff view identified by label (for pre-opened files)
@@ -265,7 +265,7 @@ describe("DiffViewProvider", () => {
265265
original: { scheme: "file" }, // Different scheme due to pre-opening
266266
modified: { fsPath: "/test/file2.md" },
267267
},
268-
label: "file2.md: Original ↔ Roo's Changes (Editable)",
268+
label: `file2.md: Original ${DIFF_VIEW_LABEL_SEPARATOR} (Editable)`,
269269
isDirty: false,
270270
},
271271
// Regular file tab (should not be closed)
@@ -284,7 +284,7 @@ describe("DiffViewProvider", () => {
284284
original: { scheme: DIFF_VIEW_URI_SCHEME },
285285
modified: { fsPath: "/test/file4.ts" },
286286
},
287-
label: "file4.ts: Original ↔ Roo's Changes (Editable)",
287+
label: `file4.ts: Original ${DIFF_VIEW_LABEL_SEPARATOR} (Editable)`,
288288
isDirty: true,
289289
},
290290
]
@@ -317,13 +317,15 @@ describe("DiffViewProvider", () => {
317317

318318
// Verify that only the appropriate tabs were closed
319319
expect(closedTabs).toHaveLength(2)
320-
expect(closedTabs[0].label).toBe("file1.ts: Original ↔ Roo's Changes (Editable)")
321-
expect(closedTabs[1].label).toBe("file2.md: Original ↔ Roo's Changes (Editable)")
320+
expect(closedTabs[0].label).toBe(`file1.ts: Original ${DIFF_VIEW_LABEL_SEPARATOR} (Editable)`)
321+
expect(closedTabs[1].label).toBe(`file2.md: Original ${DIFF_VIEW_LABEL_SEPARATOR} (Editable)`)
322322

323323
// Verify that the regular file and dirty diff were not closed
324324
expect(closedTabs.find((t) => t.label === "file3.js")).toBeUndefined()
325325
expect(
326-
closedTabs.find((t) => t.label === "file4.ts: Original ↔ Roo's Changes (Editable)" && t.isDirty),
326+
closedTabs.find(
327+
(t) => t.label === `file4.ts: Original ${DIFF_VIEW_LABEL_SEPARATOR} (Editable)` && t.isDirty,
328+
),
327329
).toBeUndefined()
328330
})
329331
})

0 commit comments

Comments
 (0)