Skip to content

Commit 7f6d136

Browse files
committed
feat(fws): add per-file open-in-editor control to change cards (B3b, #1375)
1 parent 0e021ef commit 7f6d136

20 files changed

Lines changed: 94 additions & 18 deletions

File tree

‎webview-ui/src/components/chat/ChangeCard.tsx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ export const ChangeCard = ({ message }: { message: ClineMessage }) => {
133133
setStepRollback({ status: "pending" })
134134
}
135135

136+
// Open the changed file in the editor. The extension host resolves relative
137+
// paths against the current cwd (webviewMessageHandler "openFile"), so
138+
// normalize the "./" prefix the same way FileChangesPanel does.
139+
const openFileInEditor = (path: string) => {
140+
vscode.postMessage({ type: "openFile", text: path.startsWith("./") ? path : "./" + path })
141+
}
142+
136143
const diffBadges = (additions: number, deletions: number) =>
137144
additions > 0 || deletions > 0 ? (
138145
<span className="flex items-center gap-2 shrink-0" aria-hidden>
@@ -293,6 +300,7 @@ export const ChangeCard = ({ message }: { message: ClineMessage }) => {
293300
language="diff"
294301
isExpanded={expandedFiles.has(file.path)}
295302
onToggleExpand={() => toggleFile(file.path)}
303+
onJumpToFile={() => openFileInEditor(file.path)}
296304
diffStats={{ added: file.additions, removed: file.deletions }}
297305
/>
298306
) : (
@@ -302,6 +310,16 @@ export const ChangeCard = ({ message }: { message: ClineMessage }) => {
302310
</span>
303311
<span className="grow" />
304312
{diffBadges(file.additions, file.deletions)}
313+
<span
314+
className="codicon codicon-link-external cursor-pointer"
315+
style={{ fontSize: 13.5 }}
316+
role="button"
317+
tabIndex={0}
318+
aria-label={t("chat:changeCard.openFile")}
319+
title={t("chat:changeCard.openFile")}
320+
data-testid={`change-card-file-open-${index}`}
321+
onClick={() => openFileInEditor(file.path)}
322+
/>
305323
</div>
306324
)}
307325
</div>

‎webview-ui/src/components/chat/__tests__/ChangeCard.spec.tsx‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ vi.mock("react-i18next", () => ({
2727
"chat:changeCard.rolledBack": "Rolled back",
2828
"chat:changeCard.stepRolledBack": "Step rolled back",
2929
"chat:changeCard.rollbackFailed": "Rollback failed",
30+
"chat:changeCard.openFile": "Open file",
3031
}
3132
return map[key] || key
3233
},
@@ -325,6 +326,45 @@ describe("ChangeCard", () => {
325326
expect(screen.getByTestId("change-card-step-rollback")).toBeInTheDocument()
326327
expect(mockPostMessage).not.toHaveBeenCalledWith(expect.objectContaining({ type: "checkpointRollbackStep" }))
327328
})
329+
330+
it("posts an openFile message from both the diff-row jump icon and the no-diff-row button", () => {
331+
renderWithExtensionState(
332+
<ChangeCard
333+
message={makeCardMessage({
334+
detail: "full",
335+
files: [
336+
{ path: "src/a.ts", additions: 1, deletions: 1, diff: DIFF_A },
337+
{ path: "src/b.ts", additions: 1, deletions: 1 },
338+
],
339+
totalFiles: 2,
340+
})}
341+
/>,
342+
)
343+
344+
// Diff row: the CodeAccordion header jump icon (own aria-label).
345+
fireEvent.click(screen.getByLabelText("Open file: src/a.ts"))
346+
expect(mockPostMessage).toHaveBeenCalledWith({ type: "openFile", text: "./src/a.ts" })
347+
mockPostMessage.mockClear()
348+
349+
// No-diff row: the open control on the plain path row.
350+
fireEvent.click(screen.getByTestId("change-card-file-open-1"))
351+
expect(mockPostMessage).toHaveBeenCalledWith({ type: "openFile", text: "./src/b.ts" })
352+
})
353+
354+
it("does not double-prefix paths that already carry the ./ marker", () => {
355+
renderWithExtensionState(
356+
<ChangeCard
357+
message={makeCardMessage({
358+
detail: "summary",
359+
files: [{ path: "./src/c.ts", additions: 1, deletions: 1 }],
360+
totalFiles: 1,
361+
})}
362+
/>,
363+
)
364+
365+
fireEvent.click(screen.getByTestId("change-card-file-open-0"))
366+
expect(mockPostMessage).toHaveBeenCalledWith({ type: "openFile", text: "./src/c.ts" })
367+
})
328368
})
329369

330370
describe("ChatRow - change_card say", () => {

‎webview-ui/src/i18n/locales/ca/chat.json‎

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎webview-ui/src/i18n/locales/de/chat.json‎

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎webview-ui/src/i18n/locales/en/chat.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@
199199
"rollingBack": "Rolling back...",
200200
"rolledBack": "Rolled back",
201201
"stepRolledBack": "Step rolled back",
202-
"rollbackFailed": "Rollback failed"
202+
"rollbackFailed": "Rollback failed",
203+
"openFile": "Open file"
203204
},
204205
"checkpoint": {
205206
"regular": "Checkpoint",

‎webview-ui/src/i18n/locales/es/chat.json‎

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎webview-ui/src/i18n/locales/fr/chat.json‎

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎webview-ui/src/i18n/locales/hi/chat.json‎

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎webview-ui/src/i18n/locales/id/chat.json‎

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎webview-ui/src/i18n/locales/it/chat.json‎

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)