Skip to content

Commit 8e50737

Browse files
committed
Fixed empty quote issues.
1 parent 61b458e commit 8e50737

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecQuoteSpan.kt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ import android.graphics.Color
2222
import android.graphics.Paint
2323
import android.graphics.Rect
2424
import android.support.v4.text.TextDirectionHeuristicsCompat
25+
import android.support.v4.text.TextUtilsCompat
26+
import android.support.v4.view.ViewCompat
2527
import android.text.Layout
2628
import android.text.Spanned
29+
import android.text.TextUtils
2730
import android.text.style.LineBackgroundSpan
2831
import android.text.style.LineHeightSpan
2932
import android.text.style.QuoteSpan
3033
import android.text.style.UpdateLayout
3134
import org.wordpress.aztec.AztecAttributes
3235
import org.wordpress.aztec.formatting.BlockFormatter
36+
import java.util.Locale
3337

3438
class AztecQuoteSpan(
3539
override var nestingLevel: Int,
@@ -77,9 +81,9 @@ class AztecQuoteSpan(
7781
val marginStart: Float
7882
val marginEnd: Float
7983

80-
if (TextDirectionHeuristicsCompat.FIRSTSTRONG_LTR.isRtl(text, start, end - start)) {
81-
marginStart = (x - quoteStyle.quoteMargin).toFloat()
82-
marginEnd = (x - quoteStyle.quoteMargin + dir * quoteStyle.quoteWidth).toFloat()
84+
if (isRtlQuote(text, start, end)) {
85+
marginStart = (x - quoteStyle.quoteMargin + dir * quoteStyle.quoteWidth).toFloat()
86+
marginEnd = (x - quoteStyle.quoteMargin).toFloat()
8387
} else {
8488
marginStart = (x + quoteStyle.quoteMargin).toFloat()
8589
marginEnd = (x + quoteStyle.quoteMargin + dir * quoteStyle.quoteWidth).toFloat()
@@ -93,7 +97,7 @@ class AztecQuoteSpan(
9397

9498
override fun drawBackground(c: Canvas, p: Paint, left: Int, right: Int,
9599
top: Int, baseline: Int, bottom: Int,
96-
text: CharSequence?, start: Int, end: Int,
100+
text: CharSequence, start: Int, end: Int,
97101
lnum: Int) {
98102
val alpha: Int = (quoteStyle.quoteBackgroundAlpha * 255).toInt()
99103

@@ -107,7 +111,7 @@ class AztecQuoteSpan(
107111
val quoteBackgroundStart: Int
108112
val quoteBackgroundEnd: Int
109113

110-
if (TextDirectionHeuristicsCompat.FIRSTSTRONG_LTR.isRtl(text, start, end - start)) {
114+
if (isRtlQuote(text, start, end)) {
111115
quoteBackgroundStart = left
112116
quoteBackgroundEnd = right - quoteStyle.quoteMargin
113117
} else {
@@ -120,4 +124,13 @@ class AztecQuoteSpan(
120124
c.drawRect(rect, p)
121125
p.color = paintColor
122126
}
127+
128+
private fun isRtlQuote(text: CharSequence, start: Int, end: Int): Boolean {
129+
return if (start == end || TextUtils.isEmpty(text) || text.substring(start, end) == "\n") {
130+
TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL
131+
} else {
132+
TextDirectionHeuristicsCompat.FIRSTSTRONG_LTR.isRtl(text, start, end - start)
133+
}
134+
}
135+
123136
}

0 commit comments

Comments
 (0)