diff --git a/packages/codemirror/codemirror.mjs b/packages/codemirror/codemirror.mjs index 29dca867..91f9fd8f 100644 --- a/packages/codemirror/codemirror.mjs +++ b/packages/codemirror/codemirror.mjs @@ -126,6 +126,7 @@ export class StrudelMirror { this.miniLocations = []; this.widgets = []; this.painters = []; + this.drawTime = drawTime; this.onDraw = onDraw; const self = this; this.id = id || s4(); @@ -151,6 +152,7 @@ export class StrudelMirror { onToggle: (started) => { replOptions?.onToggle?.(started); if (started) { + this.adjustDrawTime(); this.drawer.start(this.repl.scheduler); // stop other repls when this one is started document.dispatchEvent( @@ -177,6 +179,7 @@ export class StrudelMirror { updateWidgets(this.editor, this.widgets); updateMiniLocations(this.editor, this.miniLocations); replOptions?.afterEval?.(options); + this.adjustDrawTime(); this.drawer.invalidate(); }, }); @@ -212,6 +215,11 @@ export class StrudelMirror { }; document.addEventListener('start-repl', this.onStartRepl); } + // adjusts draw time depending on if there are painters + adjustDrawTime() { + // when no painters are set, [0,0] is enough (just highlighting) + this.drawer.setDrawTime(!!this.painters.length ? this.drawTime : [0, 0]); + } async drawFirstFrame() { if (!this.onDraw) { return; diff --git a/packages/core/draw.mjs b/packages/core/draw.mjs index ff5359e1..0d2796f1 100644 --- a/packages/core/draw.mjs +++ b/packages/core/draw.mjs @@ -145,6 +145,9 @@ export class Drawer { }, ); } + setDrawTime(drawTime) { + this.drawTime = drawTime; + } invalidate(scheduler = this.scheduler, t) { if (!scheduler) { return; diff --git a/website/src/repl/Repl2.jsx b/website/src/repl/Repl2.jsx index 641d2a91..fff89e52 100644 --- a/website/src/repl/Repl2.jsx +++ b/website/src/repl/Repl2.jsx @@ -57,10 +57,7 @@ export function Repl2({ embedded = false }) { const shouldDraw = true; const init = useCallback(({ shouldDraw }) => { - // TODO: find way to make spiral & punchcard work (if there's any) - // upping the 2nd value leads to slow eval times - // because Drawer.invalidate might query alot at one time - const drawTime = [0, 0]; + const drawTime = [-2, 2]; const drawContext = shouldDraw ? getDrawContext() : null; let onDraw; if (shouldDraw) {