57 lines
3.6 KiB
Markdown
57 lines
3.6 KiB
Markdown
# Clickable links in chat messages
|
|
|
|
- Detection (`lib/features/chat/ui/transcript/chat_links.dart`, pure): bare
|
|
`http(s)://` and `www.` links with trailing punctuation and unbalanced closing
|
|
brackets trimmed; `<https://…>`, `<mailto:…>` and `<user@host>` autolinks;
|
|
markdown destinations keep balanced parentheses and drop a `"title"`.
|
|
`chatLinkUri` is the only gate: `http`/`https` with a host, `mailto` with an
|
|
address, `www.` opened over https. Everything else stays plain text.
|
|
- Assistant markdown (`ChatMarkdownView`, also artifacts/run fields/stage
|
|
definitions) opens links through `onOpenLink` when given, else the
|
|
`ChatLinkScope` launcher (default: `url_launcher`, external application).
|
|
- Operator messages (`ChatLinkText`) keep the exact typed characters; only bare
|
|
links outside backtick code become links. Text without a link stays
|
|
`SelectableText`.
|
|
- Inline code and fenced code are never linkified.
|
|
- Click: a primary mouse press on a link belongs to the link (its recognizer
|
|
accepts on pointer down), like a press on a web page's anchor. Before, the
|
|
`SelectionArea` claimed the press as a selection drag once the pointer moved
|
|
`kPrecisePointerPanSlop` (2 px), so in the browser a click with a little
|
|
hand or trackpad drift opened nothing (headless Chrome: 0-2 px opened, 3, 5
|
|
and 8 px did not). The click still cancels past the tap slop (18 px); a
|
|
selection drag that starts on plain text still crosses links; a drag that
|
|
starts on a link selects nothing (as a browser drags an anchor). Touch,
|
|
stylus and right-click presses keep competing in the arena, so a long press
|
|
still selects and offers Copy link.
|
|
- Style: host primary colour (`CupertinoTheme.primaryColor`), underline; hover
|
|
thickens the underline (paint-only, selection survives) with a click cursor.
|
|
- Copy link: long press adds it to the selection toolbar. On native desktop the
|
|
right-click selection toolbar carries it. On the web the browser owns the
|
|
right-click menu over text, so a link handles its own secondary click and the
|
|
DOM `contextmenu` event is suppressed only while the pointer is over a link.
|
|
Do not toggle `BrowserContextMenu` for this: on web every `SelectableRegion`
|
|
rebuilds without its platform menu wrapper, remounts its subtree, throws in
|
|
`StaticSelectionContainerDelegate.hasSize` and drops the selection.
|
|
|
|
Browser check: `tool/capture/examples/chat-link-click.json` drifts a click
|
|
5 px on a link and drags a selection across links, and expects exactly one
|
|
`window.open`. Checked in headless Chrome (Nov 2026), desktop and touch
|
|
emulation (iPhone/Android/iPad user agents): tap and click open through
|
|
`window.open` with user activation active; right-click Copy link (desktop)
|
|
and long-press Copy link (touch) write the URL to `navigator.clipboard` and it
|
|
reads back. Not verified: real iOS/macOS Safari (popup and clipboard user
|
|
activation rules differ) and real devices. In headless CPU rendering the
|
|
text-selection toolbars (stock Copy/Select all as well as Copy link) draw no
|
|
surface; popup menus do, so this looks like the renderer, not the links.
|
|
|
|
Browser capture: `?links=1` on the chat fixture (`tool/perf/chat_scroll_fixture.dart`).
|
|
With the capture kit's semantics tree on, a CDP click lands on link semantics
|
|
nodes whose rects are the bounding box of a wrapped link, so verify clicks with
|
|
pointer events dispatched to `flutter-view`.
|
|
|
|
Observed, not caused by links: dragging a selection over text below a fenced
|
|
code block in the same answer also highlights the code block.
|
|
|
|
## 2026-11-03 operator check
|
|
The operator confirmed "Copy link" works in their browser; only the drifting mouse click was broken.
|