javascript - ace editor change event and setvalue - Stack Overflow

I am listening on ACE editor's change event to handle with user's input while sometimes I wil

I am listening on ACE editor's change event to handle with user's input while sometimes I will do setvalue() by js.

So is there a way to avoid the setvalue() triggering the change event?

I am listening on ACE editor's change event to handle with user's input while sometimes I will do setvalue() by js.

So is there a way to avoid the setvalue() triggering the change event?

Share Improve this question edited Jul 29, 2015 at 10:14 Johnny Willemsen 3,0021 gold badge16 silver badges17 bronze badges asked Jul 29, 2015 at 9:30 Li_XiaLi_Xia 1111 silver badge8 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

There is no way to avoid change event. But because change event is fired synchronously, you can set a flag to not handle the events created by you. Something like

var fromSetValue = false;
editor.on("change", function() {
    if (!fromSetValue) {
        // user input
    }
})

fromSetValue = true;
editor.setValue("hi")
fromSetValue = false;

You may suppress firing events before setting a new value (and/or doing other manipulations with editor), and restore it after.

const editorValueChangeHandler = () => {
  console.log('Value handled', editor.getValue());
};

editor.off('change', editorValueChangeHandler);
editor.session.setValue('newValue');
// ... other operations with editor...
editor.on('change', editorValueChangeHandler);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742329612a4423449.html

相关推荐

  • javascript - ace editor change event and setvalue - Stack Overflow

    I am listening on ACE editor's change event to handle with user's input while sometimes I wil

    13小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信