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
|
Warning Review limit reached
Next review available in: 2 minutes Limit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits within each organization. For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdds a ProseMirror plugin that inserts complete pasted tables after the containing table. Wires the plugin into enabled table editing. Adds tests for supported and unsupported selections and paste content. ChangesTable paste handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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/ |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@src/components/text-editor/prosemirror-adapter/plugins/table-paste-plugin.ts`:
- Around line 5-13: Reorder the module so the public createTablePastePlugin
export appears before the private sliceStartsWithTable helper, leaving both
implementations and behavior unchanged.
- Around line 19-46: Restrict the table-paste interception in handlePaste to
collapsed TextSelection instances by returning false when state.selection.empty
is false. Keep the existing table and slice checks unchanged so only a caret
inside a table can trigger table insertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: a578c5d9-039c-4197-9459-c249e593e82d
📒 Files selected for processing (3)
src/components/text-editor/prosemirror-adapter/plugins/table-paste-plugin.spec.tssrc/components/text-editor/prosemirror-adapter/plugins/table-paste-plugin.tssrc/components/text-editor/prosemirror-adapter/plugins/table-plugin.ts
719cf73 to
3872c97
Compare
3872c97 to
32a399e
Compare
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, slices with no top-level table) 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"
Test plan
npm run test:spec -- table-paste-pluginnpm run test:spec -- src/components/text-editornpm 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)Summary by CodeRabbit
New Features
Tests