Control of paste insert point

Hi !

pasting some html often fails for me, because current selection does not allow what i paste inside, and prosemirror opens up its belly and spill it out all over the place. Instead i’d like to control the insert point when pasting, because from the dom attributes i can already tell it’s going to need to be inserted between such or such parent of selection. I don’t think prosemirror-view currently allows that ? Is this something possible to add to prosemirror ?

You’re looking for https://prosemirror.net/docs/ref/#view.EditorProps.handlePaste, we implement custom paste logic ourselves since we allow you to drag and drop “blocks” between editors on a page and not all positions are valid.

Right ! It’s odd that i overlooked that. Maybe i tried and got lost somehow.

Actually the code is quite involved and leads to duplication of code that is already present in prosemirror:

  • get clipboard data (already in prosemirror)
  • parse data into DOM (already in prosemirror)
  • find correct position for that piece of DOM (using custom logic)
  • parse that DOM using clipboardParser, with the context position found in previous step (already in prosemirror)
  • change the “slice” content passed in argument of handlePaste
  • do not return true, let pm insert the mutated slice

It would be a lot simpler if one could just hook there and change $context depending on DOM and current value of $context.

@marijn do you think it’s reasonnable to ask for that feature ?