Skip to content

Commit

Permalink
Delay timer for preview updates
Browse files Browse the repository at this point in the history
So that preview changes only occur when done making code changes.

Paired with @santiaago on this feature
  • Loading branch information
eee-c committed May 7, 2013
1 parent e133dc1 commit 79f18cd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/editor.dart
Expand Up @@ -29,7 +29,15 @@ class Editor {
this._ace.setValue(data, -1);
this._ace.focus();
this.updatePreview();
_ace.getSession().on('change',new js.Callback.many((e,a)=>this.updatePreview()));
_ace.getSession().on('change',new js.Callback.many((e,a)=>this.resetUpdateTimer()));
}

Timer _update_timer;
void resetUpdateTimer() {
if (_update_timer != null) _update_timer.cancel();

var wait = new Duration(seconds: 1.5);
_update_timer = new Timer(wait, ()=> this.updatePreview());
}

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

// TODO: ask why onKeyDown does not work for arrow keys
document.onKeyUp.listen((e) {
if (_update_timer != null) resetUpdateTimer();
});

this._waitForAce = new Completer();
script.onLoad.listen((event) {
js.context.ace.config.set("workerPath", "packages/ice_code_editor/js/ace");
Expand Down

0 comments on commit 79f18cd

Please sign in to comment.