feat(desktop): copy table structure as documents
This commit is contained in:
1 parent
6b4a8df4eb
commit
ec5aa7a92b
12 files changed
+539
-1
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import { isTauriRuntime } from "./tauriRuntime";
|
||||
|
||||
interface ClipboardApi {
|
||||
writeText?: (text: string) => Promise<void> | void;
|
||||
}
|
||||
@@ -15,6 +17,7 @@ interface ClipboardTextarea {
|
||||
opacity?: string;
|
||||
};
|
||||
setAttribute(name: string, value: string): void;
|
||||
focus?(): void;
|
||||
select(): void;
|
||||
setSelectionRange?(start: number, end: number): void;
|
||||
}
|
||||
@@ -37,6 +40,16 @@ export async function copyToClipboard(
|
||||
text: string,
|
||||
env: ClipboardEnvironment = globalThis as unknown as ClipboardEnvironment,
|
||||
): Promise<void> {
|
||||
if (isTauriRuntime(env as unknown as Record<string, unknown>)) {
|
||||
try {
|
||||
const { writeText } = await import("@tauri-apps/plugin-clipboard-manager");
|
||||
await writeText(text);
|
||||
return;
|
||||
} catch {
|
||||
// Fall through to Web Clipboard / legacy copy when the native plugin is unavailable.
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (env.navigator?.clipboard?.writeText) {
|
||||
await env.navigator.clipboard.writeText(text);
|
||||
@@ -61,6 +74,7 @@ export async function copyToClipboard(
|
||||
|
||||
document.body.appendChild(textarea);
|
||||
try {
|
||||
textarea.focus?.();
|
||||
textarea.select();
|
||||
textarea.setSelectionRange?.(0, text.length);
|
||||
if (!document.execCommand("copy")) {
|
||||
|
||||
Reference in new issue
Block a user