@devries-cameron20 / t3code-1 / commits / d256170b34
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix: file links with line ranges open at their first line (#34006)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 10, 2026 at 11:00 UTC d256170b34776a5fc8000ca4228602665d5a0894
9 files changed +69 -10
apps/mobile/src/lib/enrichedLinkPresentation.test.ts
+3
@@ -20,12 +20,15 @@ describe("Enriched link presentation", () => {
20 "/tmp/report.md",
21 "C:\\repo\\app.tsx",
22 "app.tsx:12:3",
23 + "src/http.ts:42-64",
24 + "http.ts:42-64",
25 ]) {
26 expect(ENRICHED_INLINE_FILE_LINK_REGEX.test(path), path).toBe(true);
27 }
28 for (const text of [
29 "npm run dev",
30 "port:3000",
31 + "port:3000-3010",
32 "TODO:12",
33 "example.com",
34 "https://example.com/app.tsx",
apps/mobile/src/lib/enrichedLinkPresentation.ts
+1 -1
@@ -92,7 +92,7 @@ export function enrichedLinkVariantPattern(url: string) {
92 }
93
94 export const ENRICHED_INLINE_FILE_LINK_REGEX =
95 - /^(?!\S*:\/\/)(?:(?:\.{1,2}[\\/]|~[\\/]|\/(?:Users|home|tmp|var|etc|opt|mnt|Volumes|private|root|usr|bin|sbin|lib|lib64|srv|dev|proc|sys|run|boot|media|workspace|workspaces)\/|[A-Za-z]:[\\/])[^\s`]+|(?:[A-Za-z0-9._-]+[\\/])+[A-Za-z0-9._-]+\.[A-Za-z0-9_-]+(?::\d+){0,2}|[A-Za-z0-9._-]+\.[A-Za-z0-9_-]+:\d+(?::\d+)?)$/;
95 + /^(?!\S*:\/\/)(?:(?:\.{1,2}[\\/]|~[\\/]|\/(?:Users|home|tmp|var|etc|opt|mnt|Volumes|private|root|usr|bin|sbin|lib|lib64|srv|dev|proc|sys|run|boot|media|workspace|workspaces)\/|[A-Za-z]:[\\/])[^\s`]+|(?:[A-Za-z0-9._-]+[\\/])+[A-Za-z0-9._-]+\.[A-Za-z0-9_-]+(?::\d+(?::\d+|-\d+)?)?|[A-Za-z0-9._-]+\.[A-Za-z0-9_-]+:\d+(?::\d+|-\d+)?)$/;
96
97 export function enrichedSkillLinkRegex(skills?: ReadonlyArray<SelectableMarkdownSkill>) {
98 const names = [...new Set(skills?.map((skill) => skill.name) ?? [])].filter(Boolean);
apps/web/src/components/ChatMarkdown.tsx
+1
@@ -850,6 +850,7 @@ function useChatMarkdownState({
850 path: fileLinkMeta.filePath,
851 ...(fileLinkMeta.line !== undefined ? { line: fileLinkMeta.line } : {}),
852 ...(fileLinkMeta.column !== undefined ? { column: fileLinkMeta.column } : {}),
853 + ...(fileLinkMeta.endLine !== undefined ? { endLine: fileLinkMeta.endLine } : {}),
854 },
855 fileLinkParentSuffixByPath,
856 )}
apps/web/src/markdown-links.test.ts
+12
@@ -97,11 +97,23 @@ describe("resolveInlineCodeFileLinkMeta", () => {
97 expect(resolveInlineCodeFileLinkMeta("AGENTS.md", "/Users/julius/project")).toBeNull();
98 });
99
100 + it("opens a line range at its first line and keeps the range for the label", () => {
101 + expect(resolveInlineCodeFileLinkMeta("src/http.ts:42-64", "/repo")).toMatchObject({
102 + targetPath: "/repo/src/http.ts:42",
103 + line: 42,
104 + endLine: 64,
105 + });
106 + });
107 +
108 it("does not treat arbitrary name:digits shapes as files", () => {
109 expect(resolveInlineCodeFileLinkMeta("error:1", "/Users/julius/project")).toBeNull();
110 expect(resolveInlineCodeFileLinkMeta("TODO:12", "/Users/julius/project")).toBeNull();
111 expect(resolveInlineCodeFileLinkMeta("exit:0", "/Users/julius/project")).toBeNull();
112 expect(resolveInlineCodeFileLinkMeta("port:3000", "/Users/julius/project")).toBeNull();
113 + expect(resolveInlineCodeFileLinkMeta("port:3000-3010", "/Users/julius/project")).toBeNull();
114 + expect(
115 + resolveInlineCodeFileLinkMeta("localhost:3000-3010", "/Users/julius/project"),
116 + ).toBeNull();
117 expect(resolveInlineCodeFileLinkMeta("http:80", "/Users/julius/project")).toBeNull();
118 });
119
apps/web/src/markdown-links.ts
+2
@@ -21,6 +21,7 @@ export interface MarkdownFileLinkMeta {
21 basename: string;
22 line?: number;
23 column?: number;
24 + endLine?: number;
25 }
26
27 export function shouldOpenMarkdownFileLinkInEditor(
@@ -84,6 +85,7 @@ export function resolveMarkdownFileLinkMeta(
85 const source = href ? parseMarkdownFileLink(href) : null;
86 return {
87 ...buildFileLinkMetaFromTarget(targetPath, cwd),
88 + ...(source?.endLine !== undefined ? { endLine: source.endLine } : {}),
89 workspaceLookupPath:
90 source !== null &&
91 !isAbsolutePath(source.path) &&
packages/shared/src/fileLinks.test.ts
+18 -1
@@ -1,5 +1,10 @@
1 import { describe, expect, it } from "vite-plus/test";
2 -import { parseFileUrlHref, splitFilePathPosition, resolvePathLinkTarget } from "./fileLinks.ts";
2 +import {
3 + fileLinkLabel,
4 + parseFileUrlHref,
5 + splitFilePathPosition,
6 + resolvePathLinkTarget,
7 +} from "./fileLinks.ts";
8
9 describe("parseFileUrlHref", () => {
10 it.each([
@@ -32,6 +37,9 @@ describe("splitFilePathPosition", () => {
37 ["src/main.ts", "#L18C2", { path: "src/main.ts", line: 18, column: 2 }],
38 ["src/main.ts:3", "#L18C2", { path: "src/main.ts", line: 3 }],
39 ["src/main.ts:0", "", { path: "src/main.ts" }],
40 + ["src/main.ts:42-64", "", { path: "src/main.ts", line: 42, endLine: 64 }],
41 + ["src/main.ts", "#L42-L64", { path: "src/main.ts", line: 42, endLine: 64 }],
42 + ["src/main.ts:42-42", "", { path: "src/main.ts", line: 42 }],
43 ])("splits %s%s", (path, hash, expected) => {
44 expect(splitFilePathPosition(path, hash)).toEqual(expected);
45 });
@@ -74,3 +82,12 @@ describe("resolvePathLinkTarget", () => {
82 }
83 });
84 });
85 +
86 +describe("fileLinkLabel", () => {
87 + it.each([
88 + [{ path: "/repo/src/http.ts", line: 42, column: 7 }, "http.ts · L42:C7"],
89 + [{ path: "/repo/src/http.ts", line: 42, endLine: 64 }, "http.ts · L42–64"],
90 + ])("labels %o", (file, label) => {
91 + expect(fileLinkLabel(file, new Map())).toBe(label);
92 + });
93 +});
packages/shared/src/fileLinks.ts
+9 -3
@@ -5,9 +5,9 @@ import {
5 stripSlashPrefixedWindowsDrive,
6 } from "./path.ts";
7
8 -const POSITION_SUFFIX_CAPTURE_PATTERN = /:(\d+)(?::(\d+))?$/;
8 +const POSITION_SUFFIX_CAPTURE_PATTERN = /:(\d+)(?::(\d+)|-(\d+))?$/;
9
10 -const POSITION_HASH_PATTERN = /^#L(\d+)(?:C(\d+))?$/i;
10 +const POSITION_HASH_PATTERN = /^#L(\d+)(?:C(\d+)|-L?(\d+))?$/i;
11
12 /** Keeps paths percent-encoded to avoid double decoding; non-localhost authorities become UNC shares. */
13 export function parseFileUrlHref(
@@ -32,6 +32,8 @@ export interface FilePathPosition {
32 readonly path: string;
33 readonly line?: number;
34 readonly column?: number;
35 + /** The last line of a range such as `:42-64`. Editors open at `line`. */
36 + readonly endLine?: number;
37 }
38
39 export function splitFilePathPosition(path: string, hash = ""): FilePathPosition {
@@ -41,10 +43,12 @@ export function splitFilePathPosition(path: string, hash = ""): FilePathPosition
43
44 const line = Number.parseInt(match[1], 10);
45 const column = match[2] === undefined ? undefined : Number.parseInt(match[2], 10);
46 + const endLine = match[3] === undefined ? undefined : Number.parseInt(match[3], 10);
47 return {
48 path: suffixMatch ? path.slice(0, -suffixMatch[0].length) : path,
49 ...(line > 0 ? { line } : {}),
50 ...(column !== undefined && column > 0 ? { column } : {}),
51 + ...(line > 0 && endLine !== undefined && endLine > line ? { endLine } : {}),
52 };
53 }
54
@@ -171,7 +175,9 @@ export function fileLinkLabel(
175 return [
176 fileBasename(file.path),
177 suffix,
174 - file.line ? `L${file.line}${file.column ? `:C${file.column}` : ""}` : undefined,
178 + file.line
179 + ? `L${file.line}${file.endLine ? `–${file.endLine}` : file.column ? `:C${file.column}` : ""}`
180 + : undefined,
181 ]
182 .filter(Boolean)
183 .join(" · ");
packages/shared/src/markdownLinks.test.ts
+17
@@ -15,6 +15,8 @@ describe("isMarkdownFileLinkLabel", () => {
15 ["validates the input", "/repo/src/example.ts:12", false],
16 ["example.ts:12", "/repo/src/example.ts:12", true],
17 ["example.ts:99", "/repo/src/example.ts:12", false],
18 + ["example.ts:12-20", "/repo/src/example.ts:12-20", true],
19 + ["example.ts:12-20", "/repo/src/example.ts:12", false],
20 ])("classifies %s for %s", (label, href, expected) => {
21 expect(isMarkdownFileLinkLabel(label, href)).toBe(expected);
22 });
@@ -25,6 +27,8 @@ describe("inlineCodeFilePathCandidate", () => {
27 it.each([
28 ["src\\main.ts", "src/main.ts"],
29 ["allocator.cc:217", "allocator.cc:217"],
30 + ["src/http.ts:42-64", "src/http.ts:42-64"],
31 + ["http.ts:42-64", "http.ts:42-64"],
32 ["origin/main", null],
33 ["z-ai/glm-5.3", null],
34 ["share/man/ls.1", "share/man/ls.1"],
@@ -101,6 +105,19 @@ describe("parseMarkdownFileLink", () => {
105 expect(parseMarkdownFileLink("/srv/app/Makefile")).toEqual({ path: "/srv/app/Makefile" });
106 });
107
108 + it("reads line ranges and opens them at their first line", () => {
109 + expect(parseMarkdownFileLink("/repo/src/http.ts:42-64")).toEqual({
110 + path: "/repo/src/http.ts",
111 + line: 42,
112 + endLine: 64,
113 + });
114 + expect(parseMarkdownFileLink("/repo/src/http.ts#L42-L64")).toEqual({
115 + path: "/repo/src/http.ts",
116 + line: 42,
117 + endLine: 64,
118 + });
119 + });
120 +
121 it("reads positions from suffixes and line anchors", () => {
122 expect(parseMarkdownFileLink("/Users/julius/project/src/main.ts#L42C7")).toEqual({
123 path: "/Users/julius/project/src/main.ts",
packages/shared/src/markdownLinks.ts
+6 -5
@@ -18,17 +18,17 @@ const RELATIVE_PATH_PREFIX_PATTERN = /^(~\/|\.{1,2}\/)/;
18 // `(group)/[id]/+page.svelte`, `@scope/pkg`). The final segment is optional so an explicit
19 // folder link may end in `/` (`patches/`, `docs/My Folder/`). A bare name with no slash still fails.
20 const RELATIVE_FILE_PATH_PATTERN =
21 - /^(?:[\p{L}\p{M}\p{N}._$+@()[\]-]+(?: +[\p{L}\p{M}\p{N}._$+@()[\]-]+)*\/)+(?:[\p{L}\p{M}\p{N}._$+@()[\]-]+(?: +[\p{L}\p{M}\p{N}._$+@()[\]-]+)*(?::\d+){0,2})?$/u;
21 + /^(?:[\p{L}\p{M}\p{N}._$+@()[\]-]+(?: +[\p{L}\p{M}\p{N}._$+@()[\]-]+)*\/)+(?:[\p{L}\p{M}\p{N}._$+@()[\]-]+(?: +[\p{L}\p{M}\p{N}._$+@()[\]-]+)*(?::\d+(?::\d+|-\d+)?)?)?$/u;
22
23 // No `@` here: `me@example.com` is an address, not a file.
24 const RELATIVE_FILE_NAME_PATTERN =
25 - /^[\p{L}\p{M}\p{N}._$+()[\]-]+(?: +[\p{L}\p{M}\p{N}._$+()[\]-]+)*\.[\p{L}\p{M}\p{N}_-]+(?::\d+){0,2}$/u;
25 + /^[\p{L}\p{M}\p{N}._$+()[\]-]+(?: +[\p{L}\p{M}\p{N}._$+()[\]-]+)*\.[\p{L}\p{M}\p{N}_-]+(?::\d+(?::\d+|-\d+)?)?$/u;
26
27 const EXTERNAL_SCHEME_PATTERN = /^([A-Za-z][A-Za-z0-9+.-]*):(.*)$/;
28
29 -const POSITION_SUFFIX_PATTERN = /:\d+(?::\d+)?$/;
29 +const POSITION_SUFFIX_PATTERN = /:\d+(?::\d+|-\d+)?$/;
30
31 -const POSITION_ONLY_PATTERN = /^\d+(?::\d+)?$/;
31 +const POSITION_ONLY_PATTERN = /^\d+(?::\d+|-\d+)?$/;
32
33 const INLINE_CODE_DISQUALIFIER_PATTERN = /[\s`]/;
34
@@ -256,7 +256,8 @@ export function isMarkdownFileLinkLabel(label: string, href: string): boolean {
256 const labelPosition = splitFilePathPosition(label.trim());
257 if (
258 (labelPosition.line !== undefined && labelPosition.line !== destination.line) ||
259 - (labelPosition.column !== undefined && labelPosition.column !== destination.column)
259 + (labelPosition.column !== undefined && labelPosition.column !== destination.column) ||
260 + (labelPosition.endLine !== undefined && labelPosition.endLine !== destination.endLine)
261 ) {
262 return false;
263 }