and set the doc content expression as title block+.
Now just select the whole document, and cut it.
Since the expression requires a title, so the document is not empty.
And the cursor is not in title but in the next paragraph.
Please try out both the operations below and see the final result:
Paste it back immediately
Or move the cursor to title, and then paste it back
They do NOT bring the original document content back.
What I want is that paste will bring back the original content if the cursor is in title (the beginning of the document), while throw away title but bring all the block+ back if the cursor is not in title.
Part of this was a bug in the replace code (fixed here) which would cause it to drop too much content because it ran out of ideas on where to place it. When pasting into the title itself, the problem is that the end of the title node (which is after the cursor) could not meaningfully be placed after the content. I’ve pushed this patch to work around it, but it’s probably not the ideal solution. I don’t have time to dig into it more deeply right now.
At nextjournal, we’re incurring in a similar problem for which the mentioned commits doesn’t seem to solve (we’re on release 1.2.2 of prosemirror-transform).
I suspect that the code around replace fails to fit the (right end of the) slice into the target selection.
fitting the copied slice into the target selection since this behaviour occurs only in presence of specific slice openStart/End depths (a.o. [1, 0] and [1, 3]).
Are there any properties that I can add to title schema in order to solve this?
To work around we’re currently trying to “fix” the pasted slice in our handlePaste handler when the target selection is in the title node by either:
changing the openEnd depth to 1 or 0 depending on its contents
adding an empty paragraph at the end of the slice’s fragment
I can reproduce this. The problem is that the replace-fitting code doesn’t know what to do with the piece of title left after the replace, because that doesn’t fit anywhere. This is unfortunately extremely tricky code. I’ll continue looking at this tomorrow.
I think prosemirror-transform 1.2.5-beta1 should help with this. But there’s a lot of code rewritten in that version, so I’m holding off releasing it as a normal version for now (see this thread).