Is it possible to move the caret up/down a WRAPPED line?

As I understand it, ProseMirror uses contenteditable for its front end, so the answer to my question is most likely, “No,” but I’ll ask anyway in hopes there’s a workaround.

I want to implement VIM-like navigation. That means pressing j and k keys when in VIM mode should move the caret up and down. In a code editor, that means it would jump to the next “hard” line, but as I’m building a writing tool, where hard lines are paragraphs that could span multiple visual lines, that’s no good. From the user’s perspective, they’d have jumped to the next paragraph.

Instead, I want to move the caret as it would if I had pressed the up or down arrow keys: a wrapped line at a time.

I tried artificially creating the arrow KeyboardEvents and dispatching them, but the browser ignores them. The event has to come from the user.

Does anyone have other ideas?

You could try to implement something on top of coordsAtPos and posAtCoords, but getting all the corner cases right is likely going to be painful.

So the way that would work, I’d get the caret’s current screen position, increment/decrement its y by line height, and then turn that back into a document position? Clever.

The corner cases would be things like line breaks, different fonts, font sizes, tables, pictures, etc., right? That does indeed sound painful. :grimacing: