Skip to content

Commit 9b0387d

Browse files
fix(web): triple-click selects the whole line around links and file chips (pingdotgg#32334)
1 parent e0d6aad commit 9b0387d

3 files changed

Lines changed: 58 additions & 5 deletions

File tree

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,42 @@ describe("ChatMarkdown inline code selection", () => {
579579
await userEvent.dblClick(fenced, { position: { x: 4, y: 4 } });
580580
expect(window.getSelection()?.toString()).toBe("fenced");
581581
});
582+
583+
it("selects the whole line on triple-click beside a favicon link or a file chip", async () => {
584+
setup();
585+
await using screen = await renderText(
586+
"Before [docs](https://example.com/docs) after words\n\nBefore [App.tsx](/tmp/project/src/App.tsx) after words",
587+
);
588+
const tripleClickWord = async (paragraph: HTMLElement, word: string) => {
589+
const text = [...paragraph.childNodes].find((node) => node.textContent?.includes(word))!;
590+
const range = document.createRange();
591+
range.setStart(text, text.textContent!.indexOf(word));
592+
range.setEnd(text, text.textContent!.indexOf(word) + word.length);
593+
const wordBox = range.getBoundingClientRect();
594+
const paragraphBox = paragraph.getBoundingClientRect();
595+
window.getSelection()?.removeAllRanges();
596+
await userEvent.tripleClick(paragraph, {
597+
position: {
598+
x: wordBox.left - paragraphBox.left + wordBox.width / 2,
599+
y: wordBox.top - paragraphBox.top + wordBox.height / 2,
600+
},
601+
});
602+
return window.getSelection()?.toString().trim();
603+
};
604+
605+
const paragraphs = screen.container.querySelectorAll("p");
606+
expect(paragraphs).toHaveLength(2);
607+
const selections = [];
608+
const lines = [];
609+
for (const paragraph of paragraphs) {
610+
lines.push(paragraph.textContent?.trim(), paragraph.textContent?.trim());
611+
selections.push(
612+
await tripleClickWord(paragraph, "Before"),
613+
await tripleClickWord(paragraph, "after"),
614+
);
615+
}
616+
expect(selections).toEqual(lines);
617+
});
582618
});
583619

584620
describe("ChatMarkdown file chip tooltips", () => {

‎apps/web/src/components/chat/MarkdownExternalLink.tsx‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { sourceControlClients } from "@t3tools/client-runtime/source-control-cli
77
import { cn } from "../../lib/utils";
88
import { sourceControlIcon } from "../../sourceControlPresentation";
99

10-
const MARKDOWN_LINK_FAVICON_CLASS_NAME = "block size-full shrink-0 select-none";
10+
// Inline-level and selectable: triple-click selection stops at block-level and select-none boxes.
11+
const MARKDOWN_LINK_FAVICON_CLASS_NAME = "inline-block size-[14px] [vertical-align:-0.125em]";
1112

1213
const failedFaviconHosts = new Set<string>();
1314

@@ -23,10 +24,7 @@ const MarkdownLinkFavicon = memo(function MarkdownLinkFavicon({ host }: { host:
2324
const brandIcon = sourceControlHostIcon(host);
2425
const faviconUrl = brandIcon ? null : faviconUrlForOrigin(`https://${host}`);
2526
return (
26-
<span
27-
className="ms-[0.25em] me-[0.2em] inline-flex size-[14px] [vertical-align:-0.125em]"
28-
aria-hidden
29-
>
27+
<span className="ms-[0.25em] me-[0.2em]" aria-hidden>
3028
{brandIcon ? (
3129
brandIcon
3230
) : faviconUrl === null || failedHost === host || failedFaviconHosts.has(host) ? (

‎apps/web/src/index.css‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,25 @@ code {
20392039
text-decoration: none;
20402040
}
20412041

2042+
/* Triple-click selection stops at block-level boxes, flex items included, so file chips in
2043+
prose stay inline-level down to the icon and label. */
2044+
.chat-markdown-file-link {
2045+
display: inline-block;
2046+
overflow-x: clip;
2047+
text-overflow: ellipsis;
2048+
white-space: nowrap;
2049+
}
2050+
2051+
.chat-markdown-file-link > :is(svg, img) {
2052+
display: inline;
2053+
margin-inline-end: 0.2em;
2054+
vertical-align: -0.125em;
2055+
}
2056+
2057+
.chat-markdown-file-link > [data-slot="context-chip-label"] {
2058+
display: inline;
2059+
}
2060+
20422061
/* File links and context chips own their color and focus ring. */
20432062
.chat-markdown a:not(.chat-markdown-file-link, :has([data-slot="context-chip-label"])) {
20442063
color: var(--info-foreground);

0 commit comments

Comments
 (0)