Reputation: 101
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?
Upvotes: 5
Views: 3499
Reputation: 39
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);
Upvotes: 0
Reputation: 24104
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;
Upvotes: 7