fix: codemirror reeval

This commit is contained in:
Felix Roos 2023-05-05 15:31:04 +02:00
parent 352e647d37
commit b5b0156e08
2 changed files with 4 additions and 7 deletions

View File

@ -128,6 +128,7 @@ export const flash = (view, ms = 200) => {
export class StrudelMirror {
constructor({ root, initialCode = '', onEvaluate, onStop }) {
this.code = initialCode;
this.view = initEditor({
root,
initialCode,

View File

@ -7,7 +7,6 @@ import { funk42 } from './tunes';
import { pianoroll, getDrawOptions } from '@strudel.cycles/core';
import './style.css';
let code = funk42;
const repl = initStrudel();
const canvas = document.getElementById('roll');
canvas.width = canvas.width * 2;
@ -15,10 +14,7 @@ canvas.height = canvas.height * 2;
const editor = new StrudelMirror({
root: document.getElementById('editor'),
initialCode: code,
onChange: (v) => {
code = v.state.doc.toString();
},
initialCode: funk42,
onEvaluate,
onStop,
});
@ -28,10 +24,10 @@ async function onEvaluate() {
editor.flash();
if (!scheduler.started) {
scheduler.stop();
await evaluate(code);
await evaluate(editor.code);
drawer.start(scheduler);
} else {
await evaluate(code);
await evaluate(editor.code);
drawer.invalidate(); // this is a bit mystic
}
}