From 53e49952d8942b7d78393e8626ec32a5808006a2 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sun, 28 Dec 2025 13:10:57 +0100 Subject: [PATCH] persist code in hash --- website/src/components/Dough/dough-mirror.mjs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/website/src/components/Dough/dough-mirror.mjs b/website/src/components/Dough/dough-mirror.mjs index 5cdfeb3f6..2626787ed 100644 --- a/website/src/components/Dough/dough-mirror.mjs +++ b/website/src/components/Dough/dough-mirror.mjs @@ -9,12 +9,23 @@ import { updateMiniLocations, highlightMiniLocations, } from '@strudel/codemirror'; -import { evalScope } from '@strudel/core'; +import { evalScope, hash2code } from '@strudel/core'; import { Framer } from '@strudel/draw'; import { persistentAtom } from '@nanostores/persistent'; import { DoughRepl } from './dough-repl.mjs'; -const initialCode = '$: note("c a f e")'; +let initialCode = '$: note("c a f e")'; +if (typeof window !== 'undefined') { + try { + const codeParam = window.location.href.split('#')[1] || ''; + if (codeParam) { + initialCode = hash2code(codeParam); + } + } catch (err) { + console.error('could not init code from url'); + } +} + export const code = persistentAtom('vanilla-repl-code', initialCode, { encode: JSON.stringify, decode: JSON.parse, @@ -64,6 +75,7 @@ export class DoughMirror { this.flash(); await this.prebaked; const { miniLocations } = await this.repl.evaluate(this.code); + window.location.hash = '#' + code2hash(this.code); updateMiniLocations(this.editor, miniLocations); } stop() {