How to move cursor from child node back to parent node

I have a document like this <p><code>12</code></p>. And the <code> node is created in a InputRule of which body ends with something like this:

tr.addMark(markStart, markEnd, markType.create(attrs));
tr.removeStoredMark(markType);

return tr;

What I would love to achieve is to automatically set the cursor right after the <code> once it’s been created- <p><code>12</code> (cursor here)</p>.

I have tried setSelection in many ways to no avail, such as this:

tr.addMark(markStart, markEnd, markType.create(attrs));
tr.removeStoredMark(markType);

const resolvedPos = tr.doc.resolve(4);  // hardcoding position just to see desired effect...

tr.setSelection(new TextSelection(resolvedPos));

return tr;

Any help is appreciated…

There are no separate cursor positions before and after the </code>. There’s only one position there, which by default has the code mark active. Disabling the code mark via removeStoredMark should work, at least for immediate subsequent typing. Doesn’t it?

1 Like

It does. Maybe I can reduce the padding on my grey background color on my </code> so users won’t think to press ‘right’ key to ‘exit’ the inline <code>.

Thank you for the response and your work :bowing_man:

Yeah, padding on inline nodes is problematic like this. But the problem exists not just in ProseMirror, but also in browsers, which for the most part also don’t distinguish between cursor positions inside and outside inline tags when it comes to where to insert text.

1 Like