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
36 changes: 36 additions & 0 deletions apps/web/src/components/ChatMarkdown.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,42 @@ describe("ChatMarkdown inline code selection", () => {
await userEvent.dblClick(fenced, { position: { x: 4, y: 4 } });
expect(window.getSelection()?.toString()).toBe("fenced");
});

it("selects the whole line on triple-click beside a favicon link or a file chip", async () => {
setup();
await using screen = await renderText(
"Before [docs](https://example.com/docs) after words\n\nBefore [App.tsx](/tmp/project/src/App.tsx) after words",
);
const tripleClickWord = async (paragraph: HTMLElement, word: string) => {
const text = [...paragraph.childNodes].find((node) => node.textContent?.includes(word))!;
const range = document.createRange();
range.setStart(text, text.textContent!.indexOf(word));
range.setEnd(text, text.textContent!.indexOf(word) + word.length);
const wordBox = range.getBoundingClientRect();
const paragraphBox = paragraph.getBoundingClientRect();
window.getSelection()?.removeAllRanges();
await userEvent.tripleClick(paragraph, {
position: {
x: wordBox.left - paragraphBox.left + wordBox.width / 2,
y: wordBox.top - paragraphBox.top + wordBox.height / 2,
},
});
return window.getSelection()?.toString().trim();
};

const paragraphs = screen.container.querySelectorAll("p");
expect(paragraphs).toHaveLength(2);
const selections = [];
const lines = [];
for (const paragraph of paragraphs) {
lines.push(paragraph.textContent?.trim(), paragraph.textContent?.trim());
selections.push(
await tripleClickWord(paragraph, "Before"),
await tripleClickWord(paragraph, "after"),
);
}
expect(selections).toEqual(lines);
});
});

describe("ChatMarkdown file chip tooltips", () => {
Expand Down
8 changes: 3 additions & 5 deletions apps/web/src/components/chat/MarkdownExternalLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { sourceControlClients } from "@t3tools/client-runtime/source-control-cli
import { cn } from "../../lib/utils";
import { sourceControlIcon } from "../../sourceControlPresentation";

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

const failedFaviconHosts = new Set<string>();

Expand All @@ -23,10 +24,7 @@ const MarkdownLinkFavicon = memo(function MarkdownLinkFavicon({ host }: { host:
const brandIcon = sourceControlHostIcon(host);
const faviconUrl = brandIcon ? null : faviconUrlForOrigin(`https://${host}`);
return (
<span
className="ms-[0.25em] me-[0.2em] inline-flex size-[14px] [vertical-align:-0.125em]"
aria-hidden
>
<span className="ms-[0.25em] me-[0.2em]" aria-hidden>
{brandIcon ? (
brandIcon
) : faviconUrl === null || failedHost === host || failedFaviconHosts.has(host) ? (
Expand Down
19 changes: 19 additions & 0 deletions apps/web/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2039,6 +2039,25 @@ code {
text-decoration: none;
}

/* Triple-click selection stops at block-level boxes, flex items included, so file chips in
prose stay inline-level down to the icon and label. */
.chat-markdown-file-link {
display: inline-block;
overflow-x: clip;
text-overflow: ellipsis;
white-space: nowrap;
}

.chat-markdown-file-link > :is(svg, img) {
display: inline;
margin-inline-end: 0.2em;
vertical-align: -0.125em;
}

.chat-markdown-file-link > [data-slot="context-chip-label"] {
display: inline;
}

/* File links and context chips own their color and focus ring. */
.chat-markdown a:not(.chat-markdown-file-link, :has([data-slot="context-chip-label"])) {
color: var(--info-foreground);
Expand Down
Loading