From 4f92e60c30f3e03b03989fa5c80c130168d4d3c3 Mon Sep 17 00:00:00 2001 From: Sky Date: Wed, 20 Nov 2024 13:13:52 +0000 Subject: [PATCH] revo - trim before copy --- app/utils.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/utils.ts b/app/utils.ts index 1c359ef95..285316f50 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -19,30 +19,34 @@ export function trimTopic(topic: string) { } export async function copyToClipboard(text: string) { + const trimmedText = text.trim(); // Remove any leading or trailing whitespace + try { if (window.__TAURI__) { - window.__TAURI__.writeText(text); + await window.__TAURI__.writeText(trimmedText); } else { - await navigator.clipboard.writeText(text); + await navigator.clipboard.writeText(trimmedText); } showToast(Locale.Copy.Success); } catch (error) { const textArea = document.createElement("textarea"); - textArea.value = text; + textArea.value = trimmedText; document.body.appendChild(textArea); - textArea.focus(); textArea.select(); + try { document.execCommand("copy"); showToast(Locale.Copy.Success); } catch (error) { showToast(Locale.Copy.Failed); + } finally { + document.body.removeChild(textArea); } - document.body.removeChild(textArea); } } + export async function downloadAs(text: string, filename: string) { if (window.__TAURI__) { const result = await window.__TAURI__.dialog.save({