Skip to content

Commit 4e3270a

Browse files
committed
feat(chat): enable jump-to-file in regular chat diff accordions (#997)
1 parent 7af1a8a commit 4e3270a

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

webview-ui/src/components/chat/ChatRow.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ export const ChatRowContent = ({
420420
return (tool.content ?? tool.diff) as string | undefined
421421
}, [tool])
422422

423-
const onJumpToCreatedFile = useMemo(() => {
424-
if (!tool || tool.tool !== "newFileCreated" || !tool.path) {
423+
const onJumpToFile = useMemo(() => {
424+
if (!tool || !tool.path) {
425425
return undefined
426426
}
427427

@@ -497,7 +497,7 @@ export const ChatRowContent = ({
497497
isLoading={message.partial}
498498
isExpanded={isExpanded}
499499
onToggleExpand={handleToggleExpand}
500-
onJumpToFile={onJumpToCreatedFile}
500+
onJumpToFile={onJumpToFile}
501501
diffStats={tool.diffStats}
502502
/>
503503
</div>
@@ -536,6 +536,7 @@ export const ChatRowContent = ({
536536
isLoading={message.partial}
537537
isExpanded={isExpanded}
538538
onToggleExpand={handleToggleExpand}
539+
onJumpToFile={onJumpToFile}
539540
diffStats={tool.diffStats}
540541
/>
541542
</div>

webview-ui/src/components/chat/__tests__/ChatRow.diff-actions.spec.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,30 @@ describe("ChatRow - inline diff stats and actions", () => {
165165
})
166166
})
167167

168+
it("shows jump-to-file affordance for appliedDiff", () => {
169+
const message = createToolAskMessage({
170+
tool: "appliedDiff",
171+
path: "src/file.ts",
172+
diff: "@@ -1,1 +1,1 @@\n-old\n+new\n",
173+
diffStats: { added: 1, removed: 1 },
174+
})
175+
176+
const { container } = renderChatRow(message)
177+
const openFileIcon = container.querySelector(".codicon-link-external") as HTMLElement | null
178+
179+
expect(openFileIcon).toBeInTheDocument()
180+
if (!openFileIcon) {
181+
throw new Error("Expected external link icon for appliedDiff")
182+
}
183+
184+
fireEvent.click(openFileIcon)
185+
186+
expect(mockPostMessage).toHaveBeenCalledWith({
187+
type: "openFile",
188+
text: "./src/file.ts",
189+
})
190+
})
191+
168192
it("preserves protected and outside-workspace messaging in unified branch", () => {
169193
const outsideWorkspaceMessage = createToolAskMessage({
170194
tool: "searchAndReplace",

0 commit comments

Comments
 (0)