Skip to content

Commit

Permalink
Don't scroll to caret when stepping.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Dec 1, 2024
1 parent eab09f3 commit 381ccd8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/components/editor/CaretView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
});
Expand Down
6 changes: 4 additions & 2 deletions src/components/editor/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 381ccd8

Please sign in to comment.