A plugin that simulates a tab event? (or a simple way to move to the next proseMirror view)

Say I want to move to the next proseMirror view after pressing Enter; I tried creating a plugin that simulates the Tab event but to no avail:

 handleKeyDown(view, event) {
      console.log('go', view, event)
      if (event.key === 'Enter') {
       
        document.activeElement?.blur()

        let event = document.createEvent('Event')
        event.initEvent('keydown', true, true)
        event.keyCode = 16
        view.dispatchEvent(event)

        return true
      }
}

I’m aware JS doesn’t really allow one to simulate a native keypress; just wondering if Prosemirror has a simple way to move to the next proseMirror view (acheiving the same thing as pressing tab)

你应该设法改变选区的位置

ProseMirror has nothing like that, and I’m not sure how easy it is to figure out which element is the next focusable thing in the browser’s tab order in general (but in a specific situation where you do know that this shouldn’t be hard to script).

1 Like

@marijn I see! Thanks! Yeah I’m using React so I can just setState in the parent container and pass auto-focus as a prop respectively