File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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" );
You can’t perform that action at this time.
0 commit comments