Skip to content

fix(text-editor): prevent content loss when pasting tables into cells#4084

Draft
john-traas wants to merge 1 commit into
mainfrom
fix/lime-19624-table-paste-content-loss
Draft

fix(text-editor): prevent content loss when pasting tables into cells#4084
john-traas wants to merge 1 commit into
mainfrom
fix/lime-19624-table-paste-content-loss

Conversation

@john-traas

Copy link
Copy Markdown
Contributor

Summary

  • Adds a new table-paste-plugin registered before prosemirror-tables' tableEditing() so its destructive cell-grid paste cannot run when the caret is a plain TextSelection inside an existing cell
  • When the user pastes a table while the caret is inside a cell, the new plugin inserts the pasted table as a fresh sibling immediately after the enclosing table, leaving every existing cell, paragraph, and trailing row intact
  • All other paste paths (CellSelection, outside-table, non-table slice) fall through to the existing default behavior

Closes 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 in limepkg-email.

Out of scope (follow-ups)

  • Visible table borders (the _tables.scss selector is gated on :host(limel-markdown:not(.no-table-styles)) and does not match limel-prosemirror-adapter)
  • Table-management menu commands (delete table, exit to next block)

Test plan

  • Unit suite passes: npx vitest run src/components/text-editor/prosemirror-adapter/plugins/table-paste-plugin.spec.ts --project spec
  • Full text-editor specs pass: npx vitest run src/components/text-editor --project spec
  • In npm start, open text-editor-with-tables example, copy 2-3 rows from Excel, paste, then place caret inside a cell and paste again — no rows are deleted
  • Reproduce reporter sequence (paste → Enter → type → paste again) and verify all intermediate paragraphs survive
  • Confirm existing CellSelection cell-grid replace still works (select multiple cells, paste a table — selected cells replaced as before)

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e5c8d268-b52b-4be3-b270-d60c4951fa80

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/lime-19624-table-paste-content-loss

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts that intercepts paste only when selection is a TextSelection inside 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() in getTableEditingPlugins.
  • Adds spec coverage for the in-cell paste, preservation of surrounding content, non-table slice fallthrough, CellSelection fallthrough, 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.

@github-actions

Copy link
Copy Markdown

Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-4084/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants