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?
2 Answers
Reset to default 7There 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
评论列表(0条)