Skip to content

Commit e7c4090

Browse files
committed
mipsy_web: fix undo/redo
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.
1 parent f636aad commit e7c4090

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

crates/mipsy_web/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@
131131
}
132132

133133
function set_editor_value(value="") {
134-
window.editor.setValue(value);
134+
// Don't unnecesarily call editor.setValue(),
135+
// since setValue will also reset undo history.
136+
if (get_editor_value() !== value) {
137+
window.editor.setValue(value);
138+
}
135139
}
136140

137141
function get_editor_value() {

0 commit comments

Comments
 (0)