From 34cd22dfc15f7ee5ba61df5bf004105f3a0e46b7 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 29 Dec 2022 19:46:50 -0500 Subject: [PATCH] Copy URL but don't update the hash (#1458) --- playground/src/Editor/settings.ts | 7 +++++-- playground/src/Editor/utils.ts | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 playground/src/Editor/utils.ts diff --git a/playground/src/Editor/settings.ts b/playground/src/Editor/settings.ts index e67a584f9f..c6f58cd7d2 100644 --- a/playground/src/Editor/settings.ts +++ b/playground/src/Editor/settings.ts @@ -22,10 +22,13 @@ export function stringify(settings: Settings): string { /** * Persist the configuration to a URL. */ -export function persist(settingsSource: string, pythonSource: string) { - window.location.hash = lzstring.compressToEncodedURIComponent( +export async function persist(settingsSource: string, pythonSource: string) { + const hash = lzstring.compressToEncodedURIComponent( settingsSource + "$$$" + pythonSource, ); + await navigator.clipboard.writeText( + window.location.href.split("#")[0] + "#" + hash, + ); } /** diff --git a/playground/src/Editor/utils.ts b/playground/src/Editor/utils.ts new file mode 100644 index 0000000000..233b0dcc00 --- /dev/null +++ b/playground/src/Editor/utils.ts @@ -0,0 +1,7 @@ +export async function copyTextToClipboard(text: string) { + if ("clipboard" in navigator) { + return await navigator.clipboard.writeText(text); + } else { + return document.execCommand("copy", true, text); + } +}