ACE 编辑器中的 applyDeltas [英] applyDeltas in ACE editor

查看:33
本文介绍了ACE 编辑器中的 applyDeltas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 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.

谢谢
穆斯塔法

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

推荐答案

当然我已经找到了答案 -

Of course I've discovered the answer -

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.

希望这对某人有所帮助.

Hope this helps someone.

穆斯塔法

这篇关于ACE 编辑器中的 applyDeltas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆