Broken Table Pasting

I’m wrestling with some unexpected paste behavior and am wondering if I’ve found a bug in one of the ProseMirror projects.

If I copy some editor text that includes part of a table and the table comes before some normal text, and then paste that content into the editor, the content of the first cell is lifted to a paragraph before the table and the rest of the content is inserted as expected.

FromAfter

In this case, the clipboard has data that looks like:

<table data-pm-slice="4 1 []">.....</table><p>...</p>

However, if the beginning of the selection includes normal text before the table, then everything is fine:

FromBefore

In this case, the clipboard has data that looks like:

<p data-pm-slice="1 4 []">.....</p><table>...</table>

I’m just not sure if this is a bug with how the data-pm-slice value is being calculated during copy, if its how the content is being fitted in prosemirror-transform, or if there’s something wrong in the prosemirror-tables project.

If I manipulate the first test case so that the table node in the clipboard does not have a data-pm-slice attribute, then everything pastes as expected.

This behavior can be easily recreated on the demo page for prosemirror-tables: https://prosemirror-tables.netlify.app/

trying replaceSelectionWith

That does indeed seems surprising. This patch makes it so that replace-fitting won’t move content out of isolating nodes (assuming your table cells are marked isolating).

Thanks, @marijn. That patch fixes the issue. I appreciate your help.

Unsurprisingly, I tested Confluence, and it doesn’t exhibit this behavior. This has me wondering if the bug is in the prosemirror-tables project and they’ve fixed it internally or, more likely, they have some custom paste handling logic that has managed to avoid this code path.

In any event, thanks again. Happy New Year!