diff --git a/src/components/editor/CaretView.svelte b/src/components/editor/CaretView.svelte index 6e9ecb63f..ef624ec63 100644 --- a/src/components/editor/CaretView.svelte +++ b/src/components/editor/CaretView.svelte @@ -206,9 +206,9 @@ }); }); - // When caret location or view changes, tick, then scroll to it. + // When caret location or view changes and not playing, tick, then scroll to it. $effect(() => { - if (location && element) + if (location && element && $evaluation.playing) tick().then(() => { if (element) element.scrollIntoView({ block: 'nearest' }); }); diff --git a/src/components/editor/Editor.svelte b/src/components/editor/Editor.svelte index 927f48068..00201c376 100644 --- a/src/components/editor/Editor.svelte +++ b/src/components/editor/Editor.svelte @@ -278,11 +278,13 @@ // If the program contains this node, scroll it's first token into view. const stepNode = evaluator.getStepNode(); if (stepNode && source.has(stepNode)) { - // Wait for everything to render, then find the node to scroll to. + // Wait for everything to render... await tick(); + + // Then find the node to scroll to. Keep searching for a visible node, + // in case the step node is invisible. let highlight: Node | undefined = stepNode; let element = null; - // Keep searching for a visible node, in case the step node is invisible. do { element = document.querySelector(`[data-id="${highlight.id}"]`); if (element !== null) break;