Skip to content

Commit

Permalink
mipsy_web: fix undo/redo
Browse files Browse the repository at this point in the history
Calling setValue on the editor causes it to drop the current
undo/redo history, and set_editor_value() is called whenever
the user changes the source code. This resulted in undo/redo
not working at all. This commit changes set_editor_value to
only call setValue() when there's a difference between the
new and old value.

There's likely a nicer way of fixing this that involves
set_editor_value() not being called as often -- but this
change seemed least likely to introduce a bug related to
a desync between the editor's and the app's view of the
editor contents.
  • Loading branch information
XavierCooney committed May 26, 2024
1 parent f636aad commit e7c4090
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/mipsy_web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@
}

function set_editor_value(value="") {
window.editor.setValue(value);
// Don't unnecesarily call editor.setValue(),
// since setValue will also reset undo history.
if (get_editor_value() !== value) {
window.editor.setValue(value);
}
}

function get_editor_value() {
Expand Down

0 comments on commit e7c4090

Please sign in to comment.