fix: remove spans utillity - #118
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR centralizes span-removal logic on Android by adding removeSpans extension utilities for Spannable and updating existing code to use them, reducing repeated getSpans(...).forEach(removeSpan) patterns across styles and utils.
Changes:
- Added
Spannable.removeSpans(...)overloads to remove spans by (range + type) or via span arrays/lists (SpannableUtils.kt). - Refactored multiple call sites in styles and utils to use the new
removeSpansutilities for consistent span cleanup. - Tightened typing in some APIs to use
Class<out EnrichedSpan>where appropriate (e.g.,ParametrizedStyles.removeSpansForRange).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| android/src/main/java/com/swmansion/enriched/utils/Utils.kt | Replaces manual paragraph/block span removal loops with removeSpans calls. |
| android/src/main/java/com/swmansion/enriched/utils/SpannableUtils.kt | Introduces removeSpans extension overloads for span removal by range/type or by collection. |
| android/src/main/java/com/swmansion/enriched/utils/ParagraphUtils.kt | Uses removeSpans(spans) to clear existing paragraph spans before applying a new one. |
| android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt | Refactors link/mention/image span removal to use removeSpans and updates span-class typing. |
| android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt | Refactors alignment span removal to use centralized removeSpans. |
| android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt | Refactors alignment reapply logic to use removeSpans(spans). |
| android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt | Refactors inline-style span removal to use removeSpans utilities. |
💡 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 how spans are removed from text in the codebase by introducing and consistently using new
removeSpansutility extension methods. This change simplifies span removal logic, reduces code duplication, and improves readability across several style and utility classes.Core refactoring:
removeSpansextension methods toSpannable, allowing removal of spans by range and type or by directly passing span arrays or lists (SpannableUtils.kt).removeSpan) inInlineStyles,ListStyles,ParagraphStyles,ParametrizedStyles, and utility classes to use the newremoveSpansmethods.Imports and type safety:
removeSpansand updated type parameters for improved type safety, especially for span classes implementingEnrichedSpan.These changes make the codebase more maintainable and less error-prone by centralizing span removal logic.
Test Plan
Provide clear steps so another contributor can reproduce the behavior or verify the feature works.
For example:
Screenshots / Videos
Include any visual proof that helps reviewers understand the change — UI updates, bug reproduction or the result of the fix.
Compatibility