fix(custom-class): preserve HTML structure in multiline selections (#594)#595
Merged
fix(custom-class): preserve HTML structure in multiline selections (#594)#595
Conversation
) - Add 'mode' option to CustomClass: 'inline', 'block', 'auto' (default) - Implement smart block detection using DOM Range API and TreeWalker - Use extractContents + insertNode pattern instead of sel.toString() - Add toggle behavior for block mode (remove class if already present) - Add comprehensive unit tests for createCustomClass (6 new tests) Fixes #594
665dbb9 to
e0f8b44
Compare
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
Fixes #594 - When applying custom class, multiline blocks were converted to single line, losing all HTML structure (paragraphs, fonts, lists, etc.).
Root Cause
The
createCustomClass()method usedsel.toString()which returns plain text only, stripping all HTML structure.Solution
Implemented an enterprise-level solution with smart block/inline detection:
New
modeoption forCustomClassinterface:'inline'- Wrap selection in single element (legacy behavior)'block'- Apply class to each block element in selection'auto'(default) - Smart detection based on selection spanDOM Range API with
extractContents()+insertNode()pattern instead ofsel.toString()TreeWalker-based block detection for finding P, DIV, H1-H6, LI, etc.
Toggle behavior in block mode - removes class if already present
Example Usage
Changes
config.ts- ExtendedCustomClassinterface withmodeoptionangular-editor.service.ts- New implementation ofcreateCustomClass()with helper methodsangular-editor.service.spec.ts- Added 6 comprehensive unit testsTest Plan
Before/After
Before (broken):
After (fixed):