Preserve formatting when deleting content.#19970
Conversation
|
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. |
|
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:
On this branch: On master:
Scenario 2 (all content selected)<p><i>[foo</i></p>
<p><i>bar</i></p>
<p><i>bom]</i></p>And do either:
No changes to the behavior. Both master and this branch:
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 upSo, from my brief tests, I like the change. It fixes the second scenario from #10517 (comment). |
|
For reviewer/QA, please check if it solves #19777. I created the Closes link in the description. |
pszczesniak
left a comment
There was a problem hiding this comment.
Implementation looks solid, no issues found 👍
…selection parameter.
04968db to
6d169c4
Compare
… check in deleteContent funciton.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
…leteContent function.

🚀 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
Reviewer checklist
t()(if any).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.