Cut and paste does not restore the document

It is really hard to describe my questions.

I made a demo based on the basic example at https://glitch.com/edit/#!/vanilla-minotaurasaurus?path=index.js:26:17

As you see, I just added a title NodeSpec

title: {
                content: "inline*",
                defining: true,
                parseDOM: [{
                    tag: "div.mytitle"
                }],
                toDOM(_node) {
                    return ["div", {
                        class: 'mytitle'
                    }, 0]
                }
}

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.

Nice!

Now I changed the demo a bit https://glitch.com/edit/#!/vanilla-minotaurasaurus?path=index.js:37:29, added a new NodeSpec value.

Now if the cursor is at title or value node and paste the document back, everything becomes title or value.