ACE编辑器中的applyDeltas [英] applyDeltas in ACE editor
问题描述
我正在尝试将更改操作保存在Ace编辑器中,然后进行回放。下面有一些伪代码-要点是applyDeltas API对于我的编辑器似乎没有任何作用。我绑定到编辑器更改事件,将更改增量推送到数组中,然后稍后尝试播放-运行下面的代码时看不到任何错误,但是我也看不到编辑器内容更改。
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.
感谢
Mustafa
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);
}
推荐答案
我当然发现了答案-
applyDeltas(Object deltas)
API需要一个增量数组。将上面的示例代码更改为 editor.getSession()。getDocument()。applyDeltas([currentDelta])
可以正确播放。
the applyDeltas(Object deltas)
API takes an array of deltas. Changing my sample code above to editor.getSession().getDocument().applyDeltas([currentDelta])
plays back properly.
希望这对某人有帮助。
穆斯塔法
这篇关于ACE编辑器中的applyDeltas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!