Copy URL but don't update the hash (#1458)

This commit is contained in:
Charlie Marsh 2022-12-29 19:46:50 -05:00 committed by GitHub
parent 9fafe16a55
commit 34cd22dfc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -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,
);
}
/**

View File

@ -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);
}
}