Skip to content

Commit 79f18cd

Browse files
committed
Delay timer for preview updates
So that preview changes only occur when done making code changes. Paired with @santiaago on this feature
1 parent e133dc1 commit 79f18cd

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

lib/editor.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ class Editor {
2929
this._ace.setValue(data, -1);
3030
this._ace.focus();
3131
this.updatePreview();
32-
_ace.getSession().on('change',new js.Callback.many((e,a)=>this.updatePreview()));
32+
_ace.getSession().on('change',new js.Callback.many((e,a)=>this.resetUpdateTimer()));
33+
}
34+
35+
Timer _update_timer;
36+
void resetUpdateTimer() {
37+
if (_update_timer != null) _update_timer.cancel();
38+
39+
var wait = new Duration(seconds: 1.5);
40+
_update_timer = new Timer(wait, ()=> this.updatePreview());
3341
}
3442

3543
// worry about waitForAce?
@@ -128,6 +136,11 @@ class Editor {
128136
..src = "packages/ice_code_editor/js/ace/ace.js";
129137
document.head.nodes.add(script);
130138

139+
// TODO: ask why onKeyDown does not work for arrow keys
140+
document.onKeyUp.listen((e) {
141+
if (_update_timer != null) resetUpdateTimer();
142+
});
143+
131144
this._waitForAce = new Completer();
132145
script.onLoad.listen((event) {
133146
js.context.ace.config.set("workerPath", "packages/ice_code_editor/js/ace");

0 commit comments

Comments
 (0)