applyDeltas in ACE editor

2020-07-18 08:46发布

问题:

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



标签: ace-editor