How to listen `keydown` event on all keys in vim normal mode in ViewPlugin.fromClass

Thanks for the great tool.

I’m trying to make a plugin with ViewPlugin which can set scrollMargin to the editor. It should set scrollMargin to 0 if this.switch is false, which means user is operating by keyboard.

My code look likes this:

const eventHandlers = {
  mousedown(event: MouseEvent, view: EditorView) {
    this.switch = false;
  },
  keydown(event: KeyboardEvent, view: EditorView) {
    this.switch = true;
  },
}

ViewPlugin.fromClass(class {
    switch = true;
    margin = {
      top: 0,
      bottom: 0,
    }
    // ...
  }, 
  {
    eventHandlers,
    provide: [
      PluginField.scrollMargins.from(value => value.margin)
    ],
  })

But I found the key down event will only fire on modifier key in vim normal mode.

Did I miss something? Is there something wrong with my code ? And is there a way to achieve my purpose?

A scroll margin of 0 will do nothing, so I think you may be confused about what that does.

As for key events being delivered, that should happen when A) the editor has focus, and B) no higher-precedence handler already handled the event. So this is probably a matter of relative precedence in relation to the vim plugin (which I don’t know much about).

Oh, what was I going to say is temporarily pause scroll with a margin when user is operating by mouse.

But whatever, I get your point.

Now I pass entire plugin to Prec.highest and register extension with its return value, everythiing works well!

Thank you!