fix(agents): add Copy Link Address to the context menu of links in readable text (#3371)

Right-clicking a link in Agent Task chat (and other readable panes using the shared Copy menu) only offered Copy, which copied the selected label. Links now also get Copy Link Address, as in browsers; Copy keeps copying the selection, and in-page anchors get no link item.

Co-authored-by: Mr0Bread <[email protected]>
Цей коміт міститься в:
Mr0Bread authored and GitHub committed 2026-11-14 22:05:29 +08:00
1 джерело 6a93f1cce6
коміт 31016ee684
7 files changed
+84 -3

No files matched your search

+10 -3
Переглянути файл
@@ -24,14 +24,19 @@ function selectionCovers(sel: Selection | null, target: Node): boolean {
return false;
}
/** The Copy menu for a right-click on `target`, or null when it is not on readable text. */
/**
* The Copy menu for a right-click on `target`, or null when it is not on readable text. On a link
* it also offers Copy Link Address, as browsers do; Copy keeps copying the selected text.
*/
export function copyMenuFor(target: EventTarget | null): MenuItem[] | null {
const el = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
if (!el || el.closest(EDITABLE)) return null;
const sel = window.getSelection();
const text = selectionCovers(sel, el) ? sel!.toString() : "";
if (!text && !el.closest(`.${selectableText}`)) return null;
return [
const href = el.closest("a[href]")?.getAttribute("href") ?? "";
const link = href.startsWith("#") ? "" : href;
if (!text && !link && !el.closest(`.${selectableText}`)) return null;
const items: MenuItem[] = [
{
id: "copy",
label: "Copy",
@@ -41,6 +46,8 @@ export function copyMenuFor(target: EventTarget | null): MenuItem[] | null {
run: () => void copyText(text),
},
];
if (link) items.push({ id: "copy-link", label: "Copy Link Address", run: () => void copyText(link) });
return items;
}
/** Writes `text` to the clipboard; falls back to copying the live selection. */