javascripteventsace-editor

Listening to content changes in Ace editor


I have to listen to content changes in an Ace editor. I figured out many ways to do it, and I would like to know the best / most adequate / canonical way to do it.

Questions:

API references:

Additional question: when trying editSession.on('change', () => ...), I noticed the callback receives a "delta" object, whereas the callback is expected to provide no parameters. If someone has an explanation for this…


Solution

  • You can use editor.session, editor.getSession() is kept for backwards compatibility.

    The difference between change and input events, is that change event is fired synchronously for each insertion or deletion, and provides delta object that allows to keep track of changes, update positions with changes, etc. Meanwhile the input event fires 50ms after a change, and is convenient for usecases where you just want to know that something have changed.