Fix multi-cell copy and paste in rich text editor tables

What does this MR do and why?

Fixes multi-cell copy/paste in rich text editor tables. Previously, copying multiple table cells and pasting them into a table inserted all content as raw markdown into a single cell instead of distributing it across cells.

Implementation Details

Root cause (two-sided):

  1. Copy side: the copyPaste extension serializes a CellSelection slice with DOMSerializer.serializeFragment, producing orphan <tr> elements without a <table> wrapper. HTML parsers drop orphan <tr>/<td> tags, so the clipboard HTML was unusable on paste.
  2. Paste side: the copyPaste extension has EXTENSION_PRIORITY_HIGHEST and intercepted every paste before prosemirror-tables' handlePaste could run, so cells were never distributed.

A previous attempt (!237180 (closed), closed) only addressed the paste side, so copies made inside the editor still failed.

Fix:

  • Copy: multi-cell selections now write <table><tbody>...</tbody></table>-wrapped HTML to the clipboard, plus tab-separated plain text (so pasting into spreadsheets works too).
  • Paste: when pasting inside a table and the clipboard HTML contains table cells, delegate to prosemirror-tables' handlePaste, which distributes cell content across rows and columns and auto-expands the table when the pasted content overflows it — the behavior agreed on in the work item (mirrors the competitive solution).

References

Resolves #585267 (closed)

Screenshots or screen recordings

Before After

How to set up and validate locally

  1. Open the rich text editor (for example, in an issue description or wiki page)
  2. Insert a table and fill some cells
  3. Select multiple cells (click a cell, then shift-click another)
  4. Copy (Cmd/Ctrl+C)
  5. Click a cell in the same or another table
  6. Paste (Cmd/Ctrl+V)
  7. Verify the content spreads across the corresponding cells
  8. Paste a row with more cells than the table has columns and verify the table auto-expands
  9. Also verify pasting a range copied from Google Sheets or Excel distributes across cells

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Vanessa Otto

Merge request reports

Loading
Loading