2013-08-05 108 views
4

我试图在Ace编辑器中保存更改操作,然后播放它们。下面有一些伪代码 - 要点是applyDeltas API似乎没有为我的编辑器做任何事情。我绑定到编辑器更改事件,将更改变量推送到数组,并尝试稍后再播放 - 我在下面运行代码时看不到任何错误,但我也没有看到编辑器内容更改。applyDeltas在ACE编辑器

感谢
穆斯塔法

shouldRecord = true; 
myStoredArray = new Array(); 
editor.on('change', function(e) { 
    if(shouldRecord) { 
     myStoredArray.push(e.data); 
    } 
}); 


//on a button click 
shouldRecord = false; 
editor.getSession().setValue(''); //clear 
for(var currentDelta in myStoredArray) { 
    editor.getSession().getDocument().applyDeltas(currentDelta); 
} 

回答

4

当然,我发现了答案 -

applyDeltas(Object deltas) API采用增量的数组。将我的示例代码更改为editor.getSession().getDocument().applyDeltas([currentDelta])可以正确回放。

希望这可以帮助别人。

穆斯塔法

+0

我试过,但我得到的错误:遗漏的类型错误:无法读取的未定义的属性“行” ace.js 4368.我在做什么错? – bewithaman