Skip to content

Commit 01485b4

Browse files
fix(web): re-apply main's round-10 markdown fixes inside the factory
Four behavior fixes from main's inline-renderer architecture, re-expressed in the branch's extracted ChatMarkdown factory where the rebase could not carry them: - #7741: file-link tooltips show the full target path, not the shortened display form the chip already shows - #7856: ordered-list marker gutters size by marker width (string starts, negative markers, first-vs-last width) instead of digit count alone - #6439: link-href extraction uses the shared spaced-path-aware helper, so command-clicking 'my folder/file.ts' links works - #8098: file links only default to the in-app browser for browser-native documents; agent file links open in the file viewer again Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 3a4e602 commit 01485b4

1 file changed

Lines changed: 13 additions & 18 deletions

File tree

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ import {
9999
} from "../markdown-clipboard";
100100
import { remarkNormalizeListItemIndentation } from "../markdown-list-indentation";
101101
import {
102+
shouldOpenMarkdownFileLinkInBrowserByDefault,
103+
extractMarkdownLinkHrefs,
102104
normalizeMarkdownLinkDestination,
103105
resolveInlineCodeFileLinkMeta,
104106
resolveMarkdownFileLinkMeta,
@@ -250,13 +252,15 @@ function findTaskListMarkerOffset(markdown: string, listItemStart: number): numb
250252
*/
251253
export function orderedListGutterStyle(
252254
itemCount: number,
253-
start: number | undefined,
255+
start: unknown,
254256
): { "--list-gutter": string } | undefined {
255-
const firstNumber = typeof start === "number" && Number.isFinite(start) ? start : 1;
257+
const parsedStart = Number.parseInt(String(start ?? 1), 10);
258+
const firstNumber = Number.isNaN(parsedStart) ? 1 : parsedStart;
256259
const lastNumber = firstNumber + Math.max(itemCount - 1, 0);
257-
const digits = String(Math.abs(lastNumber)).length;
258-
if (digits <= 2) return undefined;
259-
return { "--list-gutter": `${digits + 1}ch` };
260+
// The width includes a negative marker's minus sign (#7856).
261+
const markerWidth = Math.max(String(firstNumber).length, String(lastNumber).length);
262+
if (markerWidth <= 2) return undefined;
263+
return { "--list-gutter": `${markerWidth + 1}ch` };
260264
}
261265

262266
const CHAT_MARKDOWN_SANITIZE_SCHEMA = {
@@ -908,7 +912,6 @@ interface MarkdownFileLinkProps {
908912
className?: string | undefined;
909913
}
910914

911-
const MARKDOWN_LINK_HREF_PATTERN = /\[[^\]]*]\(([^)\s]+)(?:\s+["'][^"']*["'])?\)/g;
912915
const MARKDOWN_FILE_LINK_CLASS_NAME =
913916
"chat-markdown-file-link cursor-pointer transition-colors hover:bg-accent/70";
914917

@@ -987,16 +990,6 @@ function extractInlineCodeSpans(text: string): string[] {
987990
return spans;
988991
}
989992

990-
function extractMarkdownLinkHrefs(text: string): string[] {
991-
const hrefs: string[] = [];
992-
for (const match of text.matchAll(MARKDOWN_LINK_HREF_PATTERN)) {
993-
const href = match[1]?.trim();
994-
if (!href) continue;
995-
hrefs.push(href);
996-
}
997-
return hrefs;
998-
}
999-
1000993
function normalizeMarkdownLinkHrefKey(href: string): string {
1001994
const normalizedHref = normalizeMarkdownLinkDestination(href);
1002995
return rewriteMarkdownFileUriHref(normalizedHref) ?? normalizedHref;
@@ -1394,7 +1387,7 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
13941387
onClick={(event) => {
13951388
event.preventDefault();
13961389
event.stopPropagation();
1397-
if (onOpenInBrowser) {
1390+
if (onOpenInBrowser && shouldOpenMarkdownFileLinkInBrowserByDefault(iconPath)) {
13981391
handleOpenInBrowser();
13991392
return;
14001393
}
@@ -1411,7 +1404,9 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
14111404
className="max-w-[min(40rem,calc(100vw-2rem))] font-mono text-[11px] leading-tight"
14121405
>
14131406
<div className="overflow-x-auto whitespace-nowrap [scrollbar-color:color-mix(in_srgb,var(--border)_78%,transparent)_transparent] [scrollbar-width:thin] [&::-webkit-scrollbar]:h-1.5 [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-thumb]:bg-[color-mix(in_srgb,var(--border)_78%,transparent)] [&::-webkit-scrollbar-track]:bg-transparent">
1414-
{displayPath}
1407+
{/* The full path: the chip already shows the shortened form, and a link
1408+
to the workspace root collapses to a bare label that repeats it. */}
1409+
{targetPath}
14151410
</div>
14161411
</TooltipPopup>
14171412
</Tooltip>

0 commit comments

Comments
 (0)