Skip to content

fix: remove spans utillity - #118

Merged
IvanIhnatsiuk merged 1 commit into
developmentfrom
fix/remove-spans-util
Jul 13, 2026
Merged

fix: remove spans utillity#118
IvanIhnatsiuk merged 1 commit into
developmentfrom
fix/remove-spans-util

Conversation

@IvanIhnatsiuk

Copy link
Copy Markdown
Collaborator

Summary

This pull request refactors how spans are removed from text in the codebase by introducing and consistently using new removeSpans utility extension methods. This change simplifies span removal logic, reduces code duplication, and improves readability across several style and utility classes.

Core refactoring:

  • Added overloaded removeSpans extension methods to Spannable, allowing removal of spans by range and type or by directly passing span arrays or lists (SpannableUtils.kt).
  • Updated all usages of manual span removal loops (i.e., iterating with removeSpan) in InlineStyles, ListStyles, ParagraphStyles, ParametrizedStyles, and utility classes to use the new removeSpans methods.

Imports and type safety:

  • Added necessary imports of removeSpans and updated type parameters for improved type safety, especially for span classes implementing EnrichedSpan.

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:

  • Steps to reproduce the bug (if this is a bug fix)
  • Steps to verify the new feature
  • Expected vs actual results
  • Any special conditions or edge cases to test

Screenshots / Videos

Include any visual proof that helps reviewers understand the change — UI updates, bug reproduction or the result of the fix.

Compatibility

OS Implemented
iOS
Android

Copilot AI left a comment

Copy link
Copy Markdown

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 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 removeSpans utilities 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.

@IvanIhnatsiuk
IvanIhnatsiuk merged commit e590f55 into development Jul 13, 2026
1 check passed
@IvanIhnatsiuk
IvanIhnatsiuk deleted the fix/remove-spans-util branch July 14, 2026 09:07
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.

2 participants