Add skipFormatContainerFallbackCheck to keep persisted Content Model path valid#3358
Open
JiuqingSong wants to merge 1 commit into
Open
Add skipFormatContainerFallbackCheck to keep persisted Content Model path valid#3358JiuqingSong wants to merge 1 commit into
JiuqingSong wants to merge 1 commit into
Conversation
…path valid When formatInsertPointWithContentModel persists the Content Model group path during DOM to Model conversion, a FormatContainer that falls back to a plain paragraph would be removed from the model, leaving the persisted path invalid. Add a skipFormatContainerFallbackCheck option that keeps the FormatContainer in that scenario so the formatting callback can still rely on the path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a DOM-to-Content-Model conversion option to preserve FormatContainer nodes when formatInsertPointWithContentModel needs a stable persisted group path during formatting.
Changes:
- Adds
skipFormatContainerFallbackCheckto create-model options/settings. - Propagates the option through
createContentModeland applies it informatContainerProcessor. - Enables the option for
formatInsertPointWithContentModeland updates/adds related tests.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
packages/roosterjs-content-model-types/lib/context/DomToModelSettings.ts |
Adds runtime setting for skipping format-container fallback. |
packages/roosterjs-content-model-types/lib/context/DomToModelOption.ts |
Exposes the new create-model option. |
packages/roosterjs-content-model-dom/lib/domToModel/processors/formatContainerProcessor.ts |
Preserves FormatContainer when the new context flag is set. |
packages/roosterjs-content-model-dom/lib/domToModel/context/createDomToModelContext.ts |
Adds explicit return type to context factory helper. |
packages/roosterjs-content-model-dom/test/domToModel/processors/formatContainerProcessorTest.ts |
Covers skip-fallback behavior for div containers and blockquote. |
packages/roosterjs-content-model-core/lib/coreApi/createContentModel/createContentModel.ts |
Propagates the option onto the DOM-to-model context. |
packages/roosterjs-content-model-core/test/coreApi/createContentModel/createContentModelTest.ts |
Tests option propagation and absence when unset. |
packages/roosterjs-content-model-api/lib/publicApi/utils/formatInsertPointWithContentModel.ts |
Enables the option for insert-point formatting to keep persisted paths valid. |
packages/roosterjs-content-model-api/test/publicApi/utils/formatInsertPointWithContentModelTest.ts |
Updates assertions for the new DOM-to-model override option. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
formatInsertPointWithContentModelpersists the Content Model group path during DOM-to-Model conversion (so the formatting callback can later reference it), aFormatContainerthat gets created for a container element (e.g. a<div>with margin/padding) can later fall back to a plain paragraph when it only wraps a single paragraph. That fallback removes theFormatContainerfrom the model, leaving the persisted path pointing at a node that no longer exists — an invalid path.This adds a
skipFormatContainerFallbackCheckoption that keeps theFormatContainerin that scenario, so the persisted path stays valid and the formatting callback works correctly.Original bug: https://outlookweb.visualstudio.com/Outlook%20Web/_workitems/edit/426559
Changes
formatContainerProcessor: skip the paragraph-fallback whencontext.skipFormatContainerFallbackCheckis set.DomToModelOption/DomToModelSettings: add the newskipFormatContainerFallbackCheckflag.createContentModel: propagate the option onto the DOM-to-Model context (set only when truthy, matching the existingif (selection)pattern so the context isn't polluted with anundefinedkey).formatInsertPointWithContentModel: passskipFormatContainerFallbackCheck: true, with a comment explaining why.Tests
formatContainerProcessortests for the skip behavior (div / div-with-id kept as FormatContainer; blockquote unaffected).createContentModelwiring tests (option propagated when set, absent otherwise).formatInsertPointWithContentModelassertions to expect the new option.All affected tests pass via
yarn test:fast, andyarn eslintis clean.🤖 Generated with Claude Code