Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions apps/web/src/components/ChatMarkdown.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,22 @@ describe("ChatMarkdown headings", () => {
});
});

describe("ChatMarkdown inline code selection", () => {
it("selects the whole inline code span on double-click, but only a word in fenced code", async () => {
setup();
await using screen = await renderText(
"Run `migration-gate --dry-run` first.\n\n```txt\nfenced-block word\n```",
);
await userEvent.dblClick(screen.getByText("migration-gate --dry-run"));
expect(window.getSelection()?.toString()).toBe("migration-gate --dry-run");

window.getSelection()?.removeAllRanges();
const fenced = screen.container.querySelector("pre code")!;
await userEvent.dblClick(fenced, { position: { x: 4, y: 4 } });
expect(window.getSelection()?.toString()).toBe("fenced");
});
});

describe("ChatMarkdown Windows file links", () => {
const environmentId = EnvironmentId.make("env-windows");
const renderWindows = (text: string, parseRawHtml: boolean) =>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Expand Down
11 changes: 11 additions & 0 deletions apps/web/src/components/ChatMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import React, {
Suspense,
type ComponentProps,
type ClipboardEvent as ReactClipboardEvent,
type MouseEvent as ReactMouseEvent,
use,
memo,
useLayoutEffect,
Expand Down Expand Up @@ -942,6 +943,11 @@ function markdownHeadingRenderer(level: 1 | 2 | 3 | 4 | 5 | 6) {
};
}

// Native word selection stops at hyphens and dots, so a double-click takes the whole span.
function selectInlineCode(event: ReactMouseEvent<HTMLElement>) {
window.getSelection()?.selectAllChildren(event.currentTarget);
}

const CHAT_MARKDOWN_COMPONENTS = {
h1: markdownHeadingRenderer(1),
h2: markdownHeadingRenderer(2),
Expand Down Expand Up @@ -1334,6 +1340,11 @@ const CHAT_MARKDOWN_COMPONENTS = {
inlineCodeFilePathCandidate(codeText) ?? codeText.trim(),
);
}
return (
<code {...props} className={className} onDoubleClick={selectInlineCode}>
{children}
</code>
);
}
return (
<code {...props} className={className}>
Expand Down
Loading