Skip to content

Commit f3bc237

Browse files
justsomelegsjuliusmarminge
authored andcommitted
Improve markdown file link UX (pingdotgg#1956)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
1 parent 5f8b0cb commit f3bc237

10 files changed

Lines changed: 662 additions & 35 deletions

apps/web/src/components/ChatMarkdown.browser.tsx

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe("ChatMarkdown", () => {
6363
);
6464

6565
try {
66-
const link = page.getByRole("link", { name: "PermissionRule.ts:1" });
66+
const link = page.getByRole("link", { name: "PermissionRule.ts · L1" });
6767
await expect.element(link).toBeInTheDocument();
6868
await expect.element(link).toHaveAttribute("href", `${filePath}#L1`);
6969

@@ -76,4 +76,66 @@ describe("ChatMarkdown", () => {
7676
await screen.unmount();
7777
}
7878
});
79+
80+
it("shows column information inline when present", async () => {
81+
const filePath =
82+
"/Users/yashsingh/p/sco/claude-code-extract/src/utils/permissions/PermissionRule.ts";
83+
const screen = await render(
84+
<ChatMarkdown text={`[PermissionRule.ts](file://${filePath}#L1C7)`} cwd="/repo/project" />,
85+
);
86+
87+
try {
88+
const link = page.getByRole("link", { name: "PermissionRule.ts · L1:C7" });
89+
await expect.element(link).toBeInTheDocument();
90+
await expect.element(link).toHaveAttribute("href", `${filePath}#L1C7`);
91+
92+
await link.click();
93+
94+
await vi.waitFor(() => {
95+
expect(openInPreferredEditorMock).toHaveBeenCalledWith(
96+
expect.anything(),
97+
`${filePath}:1:7`,
98+
);
99+
});
100+
} finally {
101+
await screen.unmount();
102+
}
103+
});
104+
105+
it("disambiguates duplicate file basenames inline", async () => {
106+
const firstPath = "/Users/yashsingh/p/t3code/apps/web/src/components/chat/MessagesTimeline.tsx";
107+
const secondPath = "/Users/yashsingh/p/t3code/apps/web/src/components/MessagesTimeline.tsx";
108+
const screen = await render(
109+
<ChatMarkdown
110+
text={`See [MessagesTimeline.tsx](file://${firstPath}) and [MessagesTimeline.tsx](file://${secondPath}).`}
111+
cwd="/repo/project"
112+
/>,
113+
);
114+
115+
try {
116+
await expect
117+
.element(page.getByRole("link", { name: "MessagesTimeline.tsx · components/chat" }))
118+
.toBeInTheDocument();
119+
await expect
120+
.element(page.getByRole("link", { name: "MessagesTimeline.tsx · src/components" }))
121+
.toBeInTheDocument();
122+
} finally {
123+
await screen.unmount();
124+
}
125+
});
126+
127+
it("keeps normal web links unchanged", async () => {
128+
const screen = await render(
129+
<ChatMarkdown text="[OpenAI](https://openai.com/docs)" cwd="/repo/project" />,
130+
);
131+
132+
try {
133+
const link = page.getByRole("link", { name: "OpenAI" });
134+
await expect.element(link).toBeInTheDocument();
135+
await expect.element(link).toHaveAttribute("href", "https://openai.com/docs");
136+
await expect.element(link).toHaveAttribute("target", "_blank");
137+
} finally {
138+
await screen.unmount();
139+
}
140+
});
79141
});

0 commit comments

Comments
 (0)