Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions apps/svelte.dev/src/routes/(authed)/playground/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
async function change_hash(hash?: string) {
let url = `${location.pathname}${location.search}`;
if (hash) {
url += `#${await compress_and_encode_text(hash)}`;
const compressed = `#${await compress_and_encode_text(hash)}`;
if (compressed === location.hash) return;
url += compressed;
}

clearTimeout(setting_hash);
Expand All @@ -110,6 +112,8 @@
}, 500);
}

let idle_timeout: any;

function onchange() {
const was_modified = modified;
modified = true;
Expand All @@ -124,6 +128,13 @@
) {
name = `${name} (edited)`;
}

// Only change after 5 seconds of inactivity to not pollute browser history
clearTimeout(idle_timeout);
idle_timeout = setTimeout(() => {
const json = JSON.stringify({ files: repl.toJSON().files });
change_hash(json);
}, 5000);
}

const svelteUrl =
Expand Down Expand Up @@ -166,7 +177,7 @@
<div
style="display: contents"
onfocusout={() => {
// Only change hash on editor blur to not pollute everyone's browser history
// Only change hash on editor blur to not pollute browser history
if (modified) {
const json = JSON.stringify({ files: repl.toJSON().files });
change_hash(json);
Expand Down
Loading