Permalink
Browse files

Delay timer for preview updates

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 79f18cd8c0df8de885d1fdef0875a760b0c9bd16
Showing with 14 additions and 1 deletion.
  1. +14 −1 lib/editor.dart
@@ -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?
@@ -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");

0 comments on commit 79f18cd

Please sign in to comment.