Skip to content

Tiptap RTE: Undo deleted blocks #19851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 6, 2025

Conversation

leekelleher
Copy link
Member

Description

Fixes #19637.

Enables RTE Blocks to be "un-deleted", with the RTE's undo action.

In the RTE property-editor base class, a state of unused (deleted) blocks is maintained, so that if an RTE's undo action restores a block in the markup, the unused block data can be re-added.

How to test?

In a Tiptap RTE, try adding a block element (with data, content and/or settings), now delete the block to remove it from the RTE, then perform an undo action (either by the undo toolbar button or keyboard shortcut CTRL+Z). The block should be restored and content/settings property data is still present.

Maintains a state of unused (deleted) blocks,
that could be restored later, e.g. with Tiptap RTE's undo action.

Fixes #19637
@Copilot Copilot AI review requested due to automatic review settings August 4, 2025 11:51
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements undo functionality for deleted blocks in the Tiptap RTE by maintaining a cache of unused block data that can be restored when the RTE's undo action brings back previously deleted blocks.

  • Adds lookup maps to cache deleted block layout, content, and settings data
  • Implements restoration logic to re-add cached block data when content keys are referenced again
  • Adds proper cleanup in the destroy method to prevent memory leaks

@nikolaj-kaplan
Copy link

Will this fix also solve a similar problem that occurs when you try to cut and paste a block?
Currently when I select a block and use ctrl-x the block disappears as expected, but I am unable to paste it elsewhere in the RTE.

@leekelleher
Copy link
Member Author

Will this fix also solve a similar problem that occurs when you try to cut and paste a block? Currently when I select a block and use ctrl-x the block disappears as expected, but I am unable to paste it elsewhere in the RTE.

@nikolaj-kaplan Yes, this patch will support cut-and-paste of block elements. 👍

Copy link
Contributor

@AndyButland AndyButland left a comment

Choose a reason for hiding this comment

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

Just testing this out - looks to work but there's a couple of glitches I found.

  1. With an entered block looking like this:
image

Once I remove it and undo to restore it, it comes back like this (note greyed out, and with a + icon instead of an edit one - though clicking the + does allow to edit):

image
  1. You can copy/paste a block within an editor, which works fine. But then if you edit the copied block, it'll update the settings on the original one too.

@leekelleher
Copy link
Member Author

  1. With an entered block looking like this:
    ...
    Once I remove it and undo to restore it, it comes back like this (note greyed out, and with a + icon instead of an edit one - though clicking the + does allow to edit):

@AndyButland, This seems to happen on variant pages. I'll look into a fix.

  1. You can copy/paste a block within an editor, which works fine. But then if you edit the copied block, it'll update the settings on the original one too.

I suspect the same happens outside of this PR. Definitely something for us to look into further. 🕵️

@leekelleher
Copy link
Member Author

@AndyButland I've patched up the issue on variant documents, ready to re-review.

@leekelleher leekelleher requested a review from AndyButland August 6, 2025 09:54
Copy link
Contributor

@AndyButland AndyButland left a comment

Choose a reason for hiding this comment

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

Working as expected now for point 1, as I understand for point 2 it's not caused in this PR so will be tackled separately.

@AndyButland AndyButland merged commit 046a3d9 into main Aug 6, 2025
25 of 27 checks passed
@AndyButland AndyButland deleted the v16/bugfix/rte-restore-deleted-blocks branch August 6, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tiptap RTE: Undo does not work with deleted Block element
3 participants