October 27, 2024
Chicago 12, Melborne City, USA
javascript

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.

  • I am only interested in content changes. The event handler should be fired when user types/deletes characters, and I don’t need to know the content.
  • There is no "multi-editor": single editor session, no tabs. Though, for the future, supporting multiple sessions may be interesting, if there is no additional cost.

Questions:

  • Should I use Editor or EditSession?
  • If using the edit session, should I access it using the getter or directly the property? (getter should be the recommended one, but the property is exposed as well…)
  • Should I listen to "change" or "input"? Notes:
    • Native <textarea>’s use "input".
    • There are editor.on('input', ...), editor.on('change', ...), editSession.on('change', ...), but not editSession.on('input', ...).

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…



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video