@@ -53,7 +53,8 @@ import java.util.ArrayList
5353class AztecTagHandler (val context : Context , val plugins : List <IAztecPlugin > = ArrayList ()) : Html.TagHandler {
5454 private val loadingDrawable: Drawable
5555
56- private val markStack = mutableListOf<Any >()
56+ // Simple LIFO stack to track the html tag nesting for easy reference when we need to handle the ending of a tag
57+ private val tagStack = mutableListOf<Any >()
5758
5859 init {
5960 val styles = context.obtainStyledAttributes(R .styleable.AztecText )
@@ -179,20 +180,20 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
179180 }
180181
181182 private fun start (output : Editable , mark : Any ) {
182- markStack .add(mark)
183+ tagStack .add(mark)
183184
184185 output.setSpan(mark, output.length, output.length, Spanned .SPAN_MARK_MARK )
185186 }
186187
187188 private fun end (output : Editable , kind : Class <* >) {
188- // Get the most recent mark from the stack.
189- // This is a speed optimization instead of getting it from the spannable via `getLast()`
190- val last = if (markStack .size > 0 && kind.equals(markStack[markStack .size - 1 ].javaClass)) {
191- markStack .removeAt(markStack .size - 1 ) // remove and return the top mark on the stack
189+ // Get most recent tag type from the stack instead of `getLast()`. This is a speed optimization as `getLast()`
190+ // doesn't know that the tags are in fact nested and in pairs (since it's html)
191+ val last = if (tagStack .size > 0 && kind.equals(tagStack[tagStack .size - 1 ].javaClass)) {
192+ tagStack .removeAt(tagStack .size - 1 ) // remove and return the top mark on the stack
192193 } else {
193- // Warning: the marks stack is apparently incosistent at this point
194+ // Warning: the tags stack is apparently inconsistent at this point
194195
195- // fall back to getting the last mark from the Spannable
196+ // fall back to getting the last tag type from the Spannable
196197 output.getLast(kind)
197198 }
198199
0 commit comments