fix: open agent file links that carry line-range selectors (#1412)

This commit is contained in:
Clément Fiere
2026-06-17 21:32:40 +02:00
committed by GitHub
parent 67037fd936
commit a71ee2e2c1
14 changed files with 798 additions and 52 deletions
@@ -198,6 +198,29 @@ describe("markdownComponents", () => {
});
});
describe("markdownComponents omp read selectors", () => {
afterEach(() => {
cleanup();
openFile.mockClear();
appState.value.tasks.activeSessionId = "session-1";
appState.value.taskSessions.items = {
"session-1": { worktree_path: "/root/.kandev/tasks/example/kandev" },
};
});
it("opens file links with omp range and multi-range selectors in the editor", () => {
render(<Markdown>{"[readme](docs/README.md:16-20)"}</Markdown>);
fireEvent.click(screen.getByRole("link", { name: "readme" }));
expect(openFile).toHaveBeenCalledWith("docs/README.md");
});
it("opens file links with omp multi-range and mode selectors in the editor", () => {
render(<Markdown>{"[readme](docs/README.md:5-16,960-973:raw)"}</Markdown>);
fireEvent.click(screen.getByRole("link", { name: "readme" }));
expect(openFile).toHaveBeenCalledWith("docs/README.md");
});
});
describe("normalizeMarkdown", () => {
it("splits a glued 4-backtick close", () => {
const input = "````go\nfunc f() {\n ...\n}````\nprose continues here";
@@ -80,8 +80,12 @@ function stripHashAndQuery(href: string): string {
return href.split(/[?#]/, 1)[0] ?? "";
}
// Strip a trailing source-location / omp read selector so a file link resolves
// to the bare path: ":42", ":42:5", and omp ranges like ":16-20", ":50+150",
// ":5-16,960-973", ":2-4:raw", ":raw", ":conflicts".
function stripSourceLocationSuffix(path: string): string {
return path.replace(/:\d+(?::\d+)?$/, "");
const part = String.raw`\d+(?:[-+]\d+)?(?:,\d+(?:[-+]\d+)?)*|raw|conflicts`;
return path.replace(new RegExp(`:(?:${part})(?::(?:${part}))*$`), "");
}
function decodeHrefPath(href: string): string | null {