I am wondering if the paste logic in Prose Mirror only takes into account the schema node type when determining whether to add a pasted node into the current node at the spot of the paste, or if it also takes into account any attributes.
In my implementation, I use a single node type to signify all paragraphs (each with different margins, caps settings etc), using an attribute to specify which specific type it is. Thus, I have a set schema and can create any number of different paragraph types dynamically. So, when I copy an entire paragraph (with the following carriage return by dragging down to the start of the next paragraph) and paste it at the start of a different paragraph type, it is inserted as a new paragraph (that’s good) but the inserted paragraph’s attributes are set to the spot where the caret was, changing the type of the inserted paragraph.
In looking at the PM basic example, if I select one node type (like a bullet list) in its entirety (click and drag down to the start of the succeeding paragraph), the paste it in at the start of different type (like a paragraph), the the bullet list is inserted above properly…is that because PM is checking the schema node type and seeing they are not the same? I want mine to do the same, but perhaps my use of a single all-encompassing node type is fooling the PM paste logic. It would be great if all pastes considered attributes when deciding whether to change the node of the inserted paragraph or to just duplicate the node (and attributes) of the paste position (caret).
I just wonder if the PM paste code simply checks the schema node type (they are all ‘myPNodes’ in my editor with different attr type values) and if the node where the caret is blinking is the same node type (always myPNode as just mentioned), it is just copying the contents and leaving the attribute type parameter value the same. This causes the inserted paragraph to assume the type of whatever was the type at the insertion point (the unwanted type unless I am pasting into the same type as the one copied).
My very inelegant solution (in transformPasted) is to look at the node types (the ones being copied and the place where the insertion will be) and to then manually inserting empty paragraph fragments before and/or after the slice fragments to fool the paste logic to leave the original paragraph type set (and not changed), but that also ends up often inserting blank paragraphs that I don’t really want inserted.
I hope my description is clear, this is clearly a somewhat complex issue but I definitely don’t want to even think of having to duplicate and modify your complex paste logic in the core editor.
Thanks, Marjin, setting the openStart to 0 solved the whole issue and allowed me to get rid of all the inelegant code, just shows how much complexity there is in PM and how long it takes to really get a thorough understanding of all the parameters and variables. Sigh!