# Broken Table Pasting

**URL:** <https://discuss.prosemirror.net/t/broken-table-pasting/5117>\
**Category:** Uncategorized\
**Created:** [December 23, 2022, 9:32pm UTC](https://discuss.prosemirror.net/t/broken-table-pasting/5117 "2022-12-23T21:32:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpobley](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/jpobley/32/2471_2.png) [@jpobley](https://discuss.prosemirror.net/u/jpobley)\
**Post date:** [December 23, 2022, 9:32pm UTC](https://discuss.prosemirror.net/t/broken-table-pasting/5117/1 "2022-12-23T21:32:19Z")

</div>

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](https://discuss.prosemirror.net/uploads/secondsite/original/2X/c/c76211a7f9e073d0b1124ffdb8fbb9bad4cabe08.gif)

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](https://discuss.prosemirror.net/uploads/secondsite/original/2X/1/173be50c9fbcfc017c731d914a3b4cca70357790.gif)

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/](https://prosemirror-tables.netlify.app/)

---

<div class="post-metadata">

**Author:** ![synw1024](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/synw1024/32/3215_2.png) [@synw1024](https://discuss.prosemirror.net/u/synw1024)\
**Post date:** [December 26, 2022, 4:57pm UTC](https://discuss.prosemirror.net/t/broken-table-pasting/5117/2 "2022-12-26T16:57:10Z")

</div>

trying **[replaceSelectionWith](https://prosemirror.net/docs/ref/#state.Transaction.replaceSelectionWith)**

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)\
**Post date:** [December 29, 2022, 10:03am UTC](https://discuss.prosemirror.net/t/broken-table-pasting/5117/3 "2022-12-29T10:03:36Z")

</div>

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).

> <https://github.com/ProseMirror/prosemirror-transform/commit/f3cd7d89f524286c4da209236da5838e0304bc31>
>
> FIX: Keep content in isolating nodes inside their parent when fitting a replace
> …step.
> 
> See https://discuss.prosemirror.net/t/broken-table-pasting/5117

---

<div class="post-metadata">

**Author:** ![jpobley](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/jpobley/32/2471_2.png) [@jpobley](https://discuss.prosemirror.net/u/jpobley)\
**Post date:** [December 30, 2022, 1:15am UTC](https://discuss.prosemirror.net/t/broken-table-pasting/5117/4 "2022-12-30T01:15:12Z")

</div>

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!
