fix(text-editor): prevent content loss when pasting tables into cells#4084
fix(text-editor): prevent content loss when pasting tables into cells#4084john-traas wants to merge 1 commit into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Fixes a content-loss bug in the text editor where pasting a table while the caret is inside an existing cell would destructively replace surrounding rows/paragraphs. A new table-paste-plugin registered before prosemirror-tables' tableEditing() intercepts that specific case and inserts the pasted table as a fresh sibling after the enclosing table.
Changes:
- Adds
table-paste-plugin.tsthat intercepts paste only when selection is aTextSelectioninside a table and the pasted slice starts with a<table>, inserting the pasted table as a new sibling block after the enclosing table. - Registers the new plugin before
tableEditing()ingetTableEditingPlugins. - Adds spec coverage for the in-cell paste, preservation of surrounding content, non-table slice fallthrough,
CellSelectionfallthrough, and outside-table fallthrough.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/components/text-editor/prosemirror-adapter/plugins/table-paste-plugin.ts | New plugin that intercepts in-cell table pastes and inserts them as siblings after the enclosing table. |
| src/components/text-editor/prosemirror-adapter/plugins/table-plugin.ts | Registers the new paste plugin ahead of tableEditing(). |
| src/components/text-editor/prosemirror-adapter/plugins/table-paste-plugin.spec.ts | Unit tests covering the new plugin's gate conditions and insertion behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-4084/ |
Summary
table-paste-pluginregistered beforeprosemirror-tables'tableEditing()so its destructive cell-grid paste cannot run when the caret is a plainTextSelectioninside an existing cellCellSelection, outside-table, non-table slice) fall through to the existing default behaviorCloses part of lime-19624 / Lundalogik/crm-client#1050. The reported bug is "pasting table rows in the Conversations composer deletes other rows" — confirmed in 4 environments. The composer opts into
contentType='html'legitimately, so the fix lives here, not inlimepkg-email.Out of scope (follow-ups)
_tables.scssselector is gated on:host(limel-markdown:not(.no-table-styles))and does not matchlimel-prosemirror-adapter)Test plan
npx vitest run src/components/text-editor/prosemirror-adapter/plugins/table-paste-plugin.spec.ts --project specnpx vitest run src/components/text-editor --project specnpm start, opentext-editor-with-tablesexample, copy 2-3 rows from Excel, paste, then place caret inside a cell and paste again — no rows are deletedCellSelectioncell-grid replace still works (select multiple cells, paste a table — selected cells replaced as before)