Event for cursor moving (outside of document)

I’m looking for an event when the cursor moves (either in vim or normal mode with down/up), specifically when it tries to move outside of the document. Our specific use case will just move it to another CodeMirror instance. It doesn’t look like this exists currently, so if that’s true, (1.) would this be worth committing upstream, and/or (2.) would you have a recommended approach?



What do you mean by “viewport”? CodeMirror’s definition of viewport seems to include ~10 lines above and below what’s actually visible to the user.

I think I actually meant “document” or something. If a user tries to go below where they actually can, I want it to fire an event so it can go to the next codemirror.

If there’s a few specific commands you want to override, you can do what Eloquent JavaScript does and simply extend those commands with a kludge that moves focus whenever the user executes them at the start or end of the document.

A general solution is harder – the code that does the motion will already have clipped the new cursor position to the extent of the document by the time you can have an event handler observe it, so you won’t really know whether this is a cursor event that would have moved the cursor out of the document.