From ed6f011e69db0714cb14976cf2c853fa6c49c27b Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sat, 20 Jun 2026 14:39:06 +0200 Subject: [PATCH] feat(editor): reset the playhead when a different model loads --- src/store/simulation.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/store/simulation.ts b/src/store/simulation.ts index 620c446..6613dac 100644 --- a/src/store/simulation.ts +++ b/src/store/simulation.ts @@ -61,6 +61,17 @@ export const useSimulationStore = defineStore("simulation", () => { if (playhead.value > n - 1) playhead.value = Math.max(0, n - 1) }) + // Loading a different document (sample / import / new) restarts playback from the + // top. Editing the current one keeps the same id, so the playhead stays put — and + // undo/redo restore snapshots in place (same id), so they don't jump it either. + watch( + () => modelStore.model.id, + () => { + playing.value = false + playhead.value = 0 + }, + ) + /** A node's value at the current playhead, or null when there's nothing to show. */ function valueAt(id: string): number | null { if (!active.value) return null