mirror of
https://github.com/element-hq/element-android
synced 2024-11-23 18:05:36 +03:00
Merge pull request #7501 from SpiritCroc/duplicated-pill-fixes
Fix duplicated pills when pills contain other spans
This commit is contained in:
commit
7a24e16092
2 changed files with 15 additions and 0 deletions
1
changelog.d/7501.bugfix
Normal file
1
changelog.d/7501.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Fix duplicated mention pills in some cases
|
|
@ -83,6 +83,20 @@ class PillsPostProcessor @AssistedInject constructor(
|
|||
val pillSpan = linkSpan.createPillSpan(roomId) ?: return@forEach
|
||||
val startSpan = renderedText.getSpanStart(linkSpan)
|
||||
val endSpan = renderedText.getSpanEnd(linkSpan)
|
||||
// GlideImagesPlugin causes duplicated pills if we have a nested spans in the pill span,
|
||||
// such as images or italic text.
|
||||
// Accordingly, it's better to remove all spans that are contained in this span before rendering.
|
||||
renderedText.getSpans(startSpan, endSpan, Any::class.java).forEach remove@{
|
||||
if (it !is LinkSpan) {
|
||||
// Make sure to only remove spans that are contained in this link, and not are bigger than this link, e.g. like reply-blocks
|
||||
val start = renderedText.getSpanStart(it)
|
||||
if (start < startSpan) return@remove
|
||||
val end = renderedText.getSpanEnd(it)
|
||||
if (end > endSpan) return@remove
|
||||
|
||||
renderedText.removeSpan(it)
|
||||
}
|
||||
}
|
||||
addPillSpan(renderedText, pillSpan, startSpan, endSpan)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue