Listen to Change Event

Hello and sorry for asking such a basic question. I may be just misunderstanding this new structure where everything is an object/module. I have used code mirror 5 for a long time and am now migrating to v6

In CodeMirror 5, I would subscribe to change events like so

editor.on('change', (args) => { doStuff() } )

In CodeMirror 6, I have something like this:

EditorView.updateListener.of((v: ViewUpdate) => {
  // Do something

But this fires on every key press. Thus I’m checking for focusChanged as a workaround. Is there a more direct way to just listen for the native change event?

If you are only interested in updates that change the document, check v.docChanged in your handler.

1 Like

Hey thanks for taking the time to reply.

I’m going to go with another approach to solve what I want to achieve so no worries on this but just wanted to clarify.

When I say change event I mean the native html change event: HTMLElement: change event - Web APIs | MDN

docChanged fires after a keyup. So not exactly what I’m looking for.

Ah, I see. DOM event handlers are registered with EditorView.domEventHandlers.

1 Like