fix: paragraphs styles detection - #124
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors Android EnrichedText paragraph/list style handling to make style application/removal and toolbar state detection more robust across multi-paragraph selections and zero-width spaces (ZWS).
Changes:
- Added a
Spannable.getParagraphRanges()helper to better handle paragraph iteration, including trailing-newline cases. - Refactored list/paragraph style application to build replacements (
buildStyledListReplacement,buildStyledParagraphReplacement) and apply spans per-paragraph. - Reworked selection style-state detection (including alignment) to require full paragraph coverage and consistent alignment across selected paragraphs.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| android/src/main/java/com/swmansion/enriched/utils/Utils.kt | Adds getParagraphRanges() to generate paragraph ranges including empty trailing paragraphs. |
| android/src/main/java/com/swmansion/enriched/utils/EnrichedSelection.kt | Updates paragraph/list style detection logic (including alignment consistency across paragraphs). |
| android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt | Refactors paragraph style application/removal and applies alignment to list paragraphs individually. |
| android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt | Refactors list styling to replacement-based updates and uses applyParagraphSpan for list spans. |
💡 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
This pull request refactors and improves the handling of paragraph and list styles within the Android EnrichedText editor. The changes focus on making the application and removal of styles more robust, consistent, and maintainable, especially when dealing with zero-width spaces and multi-paragraph selections. The code now uses replacement-based updates for styling, improves span boundary safety, and enhances style state detection logic.
Refactoring and Consistency Improvements
buildStyledListReplacementandbuildStyledParagraphReplacement), ensuring more consistent handling of zero-width spaces and multi-paragraph selections.Style State Detection and Emission
getCoveredParagraphStyleStartand enhancing alignment handling.Span Application and Alignment
applyParagraphSpaninstead of directsetSpancalls for list styles, improving the reliability of span application over paragraphs.Code Quality and Safety
coerceAtMost,coerceAtLeast,coerceIn) to prevent out-of-bounds errors.Minor Improvements
EnrichedParagraphSpanwithEnrichedSpanfor better type safety and future extensibility.Test Plan
First scenario
Second scenario
Screenshots / Videos
First scenario
Screen.Recording.2026-07-15.at.17.55.54.mov
Second scenario
Screen.Recording.2026-07-15.at.18.00.14.mov
Compatibility