bobbicodes / bobbi-lisp

Interactive Lisp environment for learning Clojure
https://bobbicodes.github.io/bobbi-lisp/
0 stars 0 forks source link

[editor] clearEval does weird things when switching editors #15

Closed bobbicodes closed 11 months ago

bobbicodes commented 11 months ago

The logic that clears the eval results is buggy, and when I'm switching between the top editor and the bottom one for the unit tests, weird things happen and it becomes extremely annoying. Fortunately the undo/redo works perfectly and always respects which editor you are in, so when it spazzes out it's never difficult to get it back to a working state.

It's difficult for me to wrap my head around it, but what it does is when you evaluate something, it first saves the code before evaluation in a global variable so that when clearEval is called (which happens on every keystroke), it dispatches a change to the editor that sets it back to what it was.

It works fine until you start doing things that I didn't have in mind when I wrote the Codemirror plugin. And when I first wrote it I only meant it to work with a single editor, so when I added the second one for the tests it messed the logic up.

At some point it would be useful to design it to better accommodate working in multiple windows.

bobbicodes commented 11 months ago

I believe the last commit did the trick. I completely separated the evaluation logic so that the variables that hold the editor state before evaluation are no longer shared between the two editors.

Additionally, the code in clearEval() now only runs if the current editor was the last one evaluated.