applyDeltas in ACE editor

别说谁变了你拦得住时间么 提交于 2019-12-06 06:20:11

问题


I'm trying to save change actions in an Ace editor and then play them back. There's some pseudo-ish code below - the gist is that the applyDeltas API doesn't seem to do anything for my editor. I bind to the editor change event, push change deltas to an array, and try to play it back later - I don't see any errors when I run the code below, but I also don't see my editor content change.

Thanks
Mustafa

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);
}

回答1:


Of course I've discovered the answer -

the applyDeltas(Object deltas) API takes an array of deltas. Changing my sample code above to editor.getSession().getDocument().applyDeltas([currentDelta]) plays back properly.

Hope this helps someone.

Mustafa



来源:https://stackoverflow.com/questions/18050128/applydeltas-in-ace-editor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!