Skip to content

Retain segments with undeletable links during model pruning#3380

Merged
JiuqingSong merged 3 commits into
masterfrom
jisong/prune-undeletable-link
Jun 24, 2026
Merged

Retain segments with undeletable links during model pruning#3380
JiuqingSong merged 3 commits into
masterfrom
jisong/prune-undeletable-link

Conversation

@JiuqingSong

Copy link
Copy Markdown
Collaborator

Summary

pruneUnselectedModel previously dropped any unselected segment, which would remove links marked as undeletable. This updates the segment-retention logic in pruneUnselectedModel.ts so a segment is also kept when its link.format.undeletable is true, even if the segment itself is not selected. This preserves undeletable links (e.g. inserted by features that require the link to survive) when pruning unselected content.

How to test

  1. Run the unit tests for the pruning util:
    yarn test:fast --testPathPattern=pruneUnselectedModel
  2. Behavioral check: build a Content Model paragraph containing an unselected text segment whose link.format.undeletable = true plus other unselected segments, then call pruneUnselectedModel.
    • Before this fix: the undeletable-link segment is removed along with the other unselected segments.
    • After this fix: the undeletable-link segment is retained while other purely-unselected segments are still pruned.

Keep segments that have link.format.undeletable set to true in
pruneUnselectedModel, even when they are not selected. This prevents
undeletable link segments from being lost during selection-based pruning.

Add unit tests covering the new behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://microsoft.github.io/roosterjs/pr-preview/pr-3380/

Built to branch gh-pages at 2026-06-24 21:38 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

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

This PR updates pruneUnselectedModel to preserve segments that belong to undeletable links while pruning away unselected content, ensuring links marked link.format.undeletable = true survive selection-based model pruning.

Changes:

  • Extend paragraph segment retention logic to keep segments with link.format.undeletable even when the segment itself is not selected.
  • Add unit tests validating undeletable-link retention (and non-retention when the link is deletable).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/roosterjs-content-model-dom/lib/domUtils/selection/pruneUnselectedModel.ts Adjusts segment filtering logic during pruning to retain undeletable-link content.
packages/roosterjs-content-model-dom/test/domUtils/selection/pruneUnselectedModelTest.ts Adds test coverage for undeletable-link retention behavior during pruning.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JiuqingSong JiuqingSong enabled auto-merge (squash) June 24, 2026 21:36
@JiuqingSong JiuqingSong merged commit b4bfffa into master Jun 24, 2026
8 checks passed
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.

3 participants