Restore selection after pm is spawned

Hi,

i’m trying to figure how i can set up this:

  • user clicks on a document
  • a node (determined by the attribute of some ancestor node) is made editable and replaced by a pm instance with same content
  • selection is restored in the pm instance, so the user gets the expected caret in the right place

I have two approaches:

  • insert a span before pm instance and posFromDOM it after to do manipulations
  • calculate pos myself

Each of which requires a lot of work :frowning: Is there anything easier ?

If your editor is going to look exactly like the original content, you can probably use the posAtCoords method.

If not, there’s an option findPositions to DOMParser.parse which might be useful, though it’s still non-trivial to go from a set of coordinates to a node/offset pair.