Fix duplicated pills when pills contain other spans
Fixes following issues: - Duplicated pills if the mention contains an image: https://github.com/SchildiChat/SchildiChat-android/issues/148 - Duplicated pills if these contain underscores: https://github.com/SchildiChat/SchildiChat-android/issues/156
This commit is contained in:
parent
76ead3f344
commit
411c8c9096
@ -83,6 +83,20 @@ class PillsPostProcessor @AssistedInject constructor(
|
|||||||
val pillSpan = linkSpan.createPillSpan(roomId) ?: return@forEach
|
val pillSpan = linkSpan.createPillSpan(roomId) ?: return@forEach
|
||||||
val startSpan = renderedText.getSpanStart(linkSpan)
|
val startSpan = renderedText.getSpanStart(linkSpan)
|
||||||
val endSpan = renderedText.getSpanEnd(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)
|
addPillSpan(renderedText, pillSpan, startSpan, endSpan)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user