@@ -24,6 +24,7 @@ import android.graphics.Rect
2424import android.support.v4.text.TextDirectionHeuristicCompat
2525import android.support.v4.text.TextDirectionHeuristicsCompat
2626import android.support.v4.text.TextUtilsCompat
27+ import android.support.v4.util.ArrayMap
2728import android.support.v4.view.ViewCompat
2829import android.text.Editable
2930import android.text.Layout
@@ -47,8 +48,8 @@ class AztecQuoteSpan(
4748 override var startBeforeCollapse: Int = - 1
4849
4950 private val rect = Rect ()
50- var margin : Int = 0
51- var offset : Int = 0
51+ private var offset : Int = 0
52+ private val quoteStart = ArrayMap < Int , Float >()
5253
5354 override val TAG : String = " blockquote"
5455
@@ -82,10 +83,10 @@ class AztecQuoteSpan(
8283 p.color = quoteStyle.quoteColor
8384
8485 val editable = text as Editable
85- val isWithinListItem = editable.getSpans(start, end, AztecListItemSpan ::class .java)
86- .any { it.nestingLevel == nestingLevel - 1 }
86+ val isWithinListItem = isWithinListItem(editable, start, end)
8787 val isRtl = isRtlQuote(text, start, end)
8888
89+ val margin: Int
8990 if (isWithinListItem) {
9091 margin = x
9192 offset = quoteStyle.quoteMargin
@@ -95,6 +96,7 @@ class AztecQuoteSpan(
9596 } else {
9697 x + quoteStyle.quoteMargin
9798 }
99+ offset = 0
98100 }
99101
100102 val marginStart: Float
@@ -103,9 +105,13 @@ class AztecQuoteSpan(
103105 if (isRtl) {
104106 marginStart = (margin + dir * quoteStyle.quoteWidth).toFloat()
105107 marginEnd = margin.toFloat()
108+
109+ quoteStart[start] = marginStart
106110 } else {
107111 marginStart = margin.toFloat()
108112 marginEnd = (margin + dir * quoteStyle.quoteWidth).toFloat()
113+
114+ quoteStart[start] = marginEnd
109115 }
110116
111117 c.drawRect(marginStart, top.toFloat(), marginEnd, bottom.toFloat(), p)
@@ -114,6 +120,11 @@ class AztecQuoteSpan(
114120 p.color = color
115121 }
116122
123+ private fun isWithinListItem (editable : Editable , start : Int , end : Int ): Boolean {
124+ return editable.getSpans(start, end, AztecListItemSpan ::class .java)
125+ .any { it.nestingLevel == nestingLevel - 1 }
126+ }
127+
117128 override fun drawBackground (c : Canvas , p : Paint , left : Int , right : Int ,
118129 top : Int , baseline : Int , bottom : Int ,
119130 text : CharSequence , start : Int , end : Int ,
@@ -130,11 +141,13 @@ class AztecQuoteSpan(
130141 val quoteBackgroundStart: Int
131142 val quoteBackgroundEnd: Int
132143
133- if (isRtlQuote(text, start, end)) {
144+ val isRtl = isRtlQuote(text, start, end)
145+
146+ if (isRtl) {
134147 quoteBackgroundStart = left
135- quoteBackgroundEnd = margin
148+ quoteBackgroundEnd = quoteStart[start]?.toInt() ? : 0
136149 } else {
137- quoteBackgroundStart = margin
150+ quoteBackgroundStart = quoteStart[start]?.toInt() ? : 0
138151 quoteBackgroundEnd = right
139152 }
140153
0 commit comments