Loading
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):
- Copy side: the
copyPasteextension serializes aCellSelectionslice withDOMSerializer.serializeFragment, producing orphan<tr>elements without a<table>wrapper. HTML parsers drop orphan<tr>/<td>tags, so the clipboard HTML was unusable on paste. - Paste side: the
copyPasteextension hasEXTENSION_PRIORITY_HIGHESTand intercepted every paste beforeprosemirror-tables'handlePastecould 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
- Open the rich text editor (for example, in an issue description or wiki page)
- Insert a table and fill some cells
- Select multiple cells (click a cell, then shift-click another)
- Copy (Cmd/Ctrl+C)
- Click a cell in the same or another table
- Paste (Cmd/Ctrl+V)
- Verify the content spreads across the corresponding cells
- Paste a row with more cells than the table has columns and verify the table auto-expands
- 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