mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-01 07:36:39 +08:00
revo - trim before copy
This commit is contained in:
parent
3320f46b64
commit
4f92e60c30
14
app/utils.ts
14
app/utils.ts
@ -19,30 +19,34 @@ export function trimTopic(topic: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function copyToClipboard(text: string) {
|
export async function copyToClipboard(text: string) {
|
||||||
|
const trimmedText = text.trim(); // Remove any leading or trailing whitespace
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (window.__TAURI__) {
|
if (window.__TAURI__) {
|
||||||
window.__TAURI__.writeText(text);
|
await window.__TAURI__.writeText(trimmedText);
|
||||||
} else {
|
} else {
|
||||||
await navigator.clipboard.writeText(text);
|
await navigator.clipboard.writeText(trimmedText);
|
||||||
}
|
}
|
||||||
|
|
||||||
showToast(Locale.Copy.Success);
|
showToast(Locale.Copy.Success);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const textArea = document.createElement("textarea");
|
const textArea = document.createElement("textarea");
|
||||||
textArea.value = text;
|
textArea.value = trimmedText;
|
||||||
document.body.appendChild(textArea);
|
document.body.appendChild(textArea);
|
||||||
textArea.focus();
|
|
||||||
textArea.select();
|
textArea.select();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
document.execCommand("copy");
|
document.execCommand("copy");
|
||||||
showToast(Locale.Copy.Success);
|
showToast(Locale.Copy.Success);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showToast(Locale.Copy.Failed);
|
showToast(Locale.Copy.Failed);
|
||||||
|
} finally {
|
||||||
|
document.body.removeChild(textArea);
|
||||||
}
|
}
|
||||||
document.body.removeChild(textArea);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function downloadAs(text: string, filename: string) {
|
export async function downloadAs(text: string, filename: string) {
|
||||||
if (window.__TAURI__) {
|
if (window.__TAURI__) {
|
||||||
const result = await window.__TAURI__.dialog.save({
|
const result = await window.__TAURI__.dialog.save({
|
||||||
|
Loading…
Reference in New Issue
Block a user