Skip to content

Preserve formatting when deleting content.#19970

Open
arkflpc wants to merge 10 commits intomasterfrom
ck/10517-preserve-formatting-delete-content
Open

Preserve formatting when deleting content.#19970
arkflpc wants to merge 10 commits intomasterfrom
ck/10517-preserve-formatting-delete-content

Conversation

@arkflpc
Copy link
Copy Markdown
Contributor

@arkflpc arkflpc commented Mar 17, 2026

🚀 Summary

Preserve formatting when deleting content.


📌 Related issues


💡 Additional information

Optional: Notes on decisions, edge cases, or anything helpful for reviewers.


🧾 Checklists

Use the following checklists to ensure important areas were not overlooked.
This does not apply to feature-branch merges.
If an item is not relevant to this type of change, simply leave it unchecked.

Author checklist

  • Is the changelog entry intentionally omitted?
  • Is the change backward-compatible?
  • Have you considered the impact on different editor setups and core interactions? (e.g., classic/inline/multi-root/many editors, typing, selection, paste, tables, lists, images, collaboration, pagination)
  • Has the change been manually verified in the relevant setups?
  • Does this change affect any of the above?
  • Is performance impacted?
  • Is accessibility affected?
  • Have tests been added that fail without this change (against regression)?
  • Have the API documentation, guides, feature digest, and related feature sections been updated where needed?
  • Have metadata files (ckeditor5-metadata.json) been updated if needed?
  • Are there any changes the team should be informed about (e.g. architectural, difficult to revert in future versions or having impact on other features)?
  • Were these changes documented (in Logbook)?

Reviewer checklist

  • PR description explains the changes and the chosen approach (especially when performance, API, or UX is affected).
  • The changelog entry is clear, user‑ or integrator-facing, and it describes any breaking changes.
  • All new external dependencies have been approved and mentioned in LICENSE.md (if any).
  • All human-readable, translateable strings in this PR been introduced using t() (if any).
  • I manually verified the change (e.g., in manual tests or documentation).
  • The target branch is correct.

Note

Medium Risk
Touches core deleteContent() behavior and selection attribute handling, which can affect typing/formatting outcomes across many editor scenarios. The change is narrowly scoped and covered by new regression tests, but it alters a widely used editing primitive.

Overview
deleteContent() now preserves document selection attributes (e.g. bold/italic) when a deletion leaves the live selection in a newly-emptied parent block, so subsequent typing keeps the pre-delete formatting.

It avoids restoring attributes when the parent was already empty (e.g. when deleting via a synthetic selection elsewhere) and keeps the existing behavior of clearing attributes when the entire content is replaced with a fresh paragraph. Tests were updated/added to cover these formatting preservation and non-restoration cases.

Written by Cursor Bugbot for commit b7ceeaf. This will update automatically on new commits. Configure here.

@arkflpc arkflpc requested a review from Mati365 March 17, 2026 14:40
@Witoso
Copy link
Copy Markdown
Member

Witoso commented Mar 18, 2026

Could we describe in the PR description the behavior that was introduced with some before/after videos? The ticket that this closes is very complex, and I wonder what feature this touches. Also, I wonder if this would close #19777.

@Reinmar
Copy link
Copy Markdown
Member

Reinmar commented Mar 19, 2026

I tested it a bit manually to get a feeling where it gets us:

Scenario 1

<p><i>foo</i></p>
<p><i>[bar]</i></p>
<p><i>bom</i></p>

And do either:

  • type "x"
  • or backspace + type "x"

On this branch: <i>x</i> (style preserved) in both cases

On master:

  • type "x" -> style was preserved
  • backspace + type "x" -> style was not preserved

Scenario 2 (all content selected)

<p><i>[foo</i></p>
<p><i>bar</i></p>
<p><i>bom]</i></p>

And do either:

  • type "x"
  • or backspace + type "x"

No changes to the behavior. Both master and this branch:

  • type "x" -> style preserved
  • backspace + type "x" -> style not preserved

That's something I wanted to maintain. You can easily clean content by ctrl+a and backspace.

Scenario 3 (all content selected but only one paragraph present)

This is an edge case of scenario 2. What if you have just one paragraph and you styled it.

It works like Scenario 1 after changes. I think it's ok and even reasonable because in such case the user would most likely be much more focused on this single paragraph. So, less likely to want to "clear all content".


Summing up

So, from my brief tests, I like the change.

It fixes the second scenario from #10517 (comment).

@Witoso
Copy link
Copy Markdown
Member

Witoso commented Mar 19, 2026

For reviewer/QA, please check if it solves #19777. I created the Closes link in the description.

Copy link
Copy Markdown
Contributor

@pszczesniak pszczesniak left a comment

Choose a reason for hiding this comment

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

Implementation looks solid, no issues found 👍

⚠️ One thing missing: changelog entry.

@pomek pomek force-pushed the ck/10517-preserve-formatting-delete-content branch from 04968db to 6d169c4 Compare April 3, 2026 09:27
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Copy link
Copy Markdown
Contributor

@pszczesniak pszczesniak left a comment

Choose a reason for hiding this comment

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

👍 from my side.

@pszczesniak pszczesniak requested a review from niegowski April 3, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

7 participants