Codemirror 6 sync scrolling of two EditorView's

Hi, I was trying to implement sync scrolling too, and found this thread, but here’s what I discovered for future reference:
Scroll events are not handled by updateListener, but rather domEventHandlers, for example:

extensions : [
  ...
  EditorView.domEventHandlers({
    scroll(event, view) {
      // handle infinite loop:
      //   early exit if mouse is not hover over current div
      const self = document.getElementById( ... )
      if (!self.matches(":hover")) { return; }
      // main logic
      const scroll = event.target.scrollTop;
      ...
    }
  }),
]

Hopefully this is correct and is useful for future readers.

1 Like