fix: copy behaviour
This commit is contained in:
@@ -283,12 +283,21 @@ export function TextSelectionToolbar() {
|
|||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const formatted = formatCopyText(text);
|
const formatted = formatCopyText(text);
|
||||||
|
// The native copy event is synchronous — we can't await the short-link
|
||||||
|
// fetch before setData, so this writes the long highlight URL. It's a
|
||||||
|
// valid fallback and stands if the async upgrade below can't run.
|
||||||
e.clipboardData?.setData("text/plain", formatted);
|
e.clipboardData?.setData("text/plain", formatted);
|
||||||
|
// Upgrade the clipboard to the shortened /share/<code> URL: copy() hands
|
||||||
|
// the Clipboard API a *promise* of the shortened text, which keeps this
|
||||||
|
// gesture's activation alive while createShortLink resolves (the same
|
||||||
|
// trick the toolbar's Copy button uses). Only when there's a URL to
|
||||||
|
// shorten in the payload.
|
||||||
|
if (formatted.includes("?hl=")) void copy(formatted);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("copy", handleCopy);
|
document.addEventListener("copy", handleCopy);
|
||||||
return () => document.removeEventListener("copy", handleCopy);
|
return () => document.removeEventListener("copy", handleCopy);
|
||||||
}, []);
|
}, [copy]);
|
||||||
|
|
||||||
// Close toolbar on mouse click outside (desktop only)
|
// Close toolbar on mouse click outside (desktop only)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user