fix(desktop): route text copies through native clipboard (#2054)

Signed-off-by: npub1qvn3cujt28pg06ehlstrxyz6ayzp06t4uc7r566vxwwgrv24hglq9zju0n <03271c724b51c287eb37fc1633105ae90417e975e63c3a6b4c339c81b155ba3e@sprout-oss.stage.blox.sqprod.co>
Co-authored-by: npub1qvn3cujt28pg06ehlstrxyz6ayzp06t4uc7r566vxwwgrv24hglq9zju0n <03271c724b51c287eb37fc1633105ae90417e975e63c3a6b4c339c81b155ba3e@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
Bradley Axen
2026-07-17 17:01:24 -07:00
committed by GitHub
parent 738d456367
commit 9f82850959
21 changed files with 100 additions and 64 deletions

View File

@@ -1,16 +1,18 @@
import { toast } from "sonner";
/**
* Copy plain text to the clipboard with a success toast, surfacing
* `writeText` rejections (permissions, unfocused document) as an error
* toast instead of an unhandled rejection.
*/
import { copyTextToSystemClipboard } from "@/shared/api/tauriMedia";
/** Write plain text through the native clipboard integration. */
export async function writeTextToClipboard(text: string): Promise<void> {
await copyTextToSystemClipboard(text);
}
/** Copy plain text and show standard success/error feedback. */
export function copyTextToClipboard(
text: string,
successMessage = "Copied to clipboard",
) {
void navigator.clipboard
.writeText(text)
void writeTextToClipboard(text)
.then(() => {
toast.success(successMessage);
})

View File

@@ -1,3 +1,5 @@
import { copyTextToSystemClipboard } from "@/shared/api/tauriMedia";
const BUZZ_CODE_BLOCK_ATTRIBUTE = "data-buzz-code-block";
function escapeHtml(value: string) {
@@ -15,13 +17,10 @@ function createBuzzCodeBlockHtml(code: string) {
export async function copyCodeBlockToClipboard(code: string) {
const clipboard = navigator.clipboard;
if (!clipboard) {
throw new Error("Clipboard API is unavailable");
}
if (
typeof ClipboardItem !== "undefined" &&
typeof clipboard.write === "function"
typeof clipboard?.write === "function"
) {
try {
await clipboard.write([
@@ -38,7 +37,7 @@ export async function copyCodeBlockToClipboard(code: string) {
}
}
await clipboard.writeText(code);
await copyTextToSystemClipboard(code);
}
export function getBuzzCodeBlockClipboardText(