@@ -68,16 +68,23 @@ abstract class AztecDynamicImageSpan(val context: Context, protected var imageDr
6868
6969 override fun getSize (paint : Paint ? , text : CharSequence? , start : Int , end : Int , metrics : Paint .FontMetricsInt ? ): Int {
7070 val sizeRect = adjustBounds(start)
71+ if (metrics != null && sizeRect.height() > 0 ) {
7172
72- if (metrics != null && sizeRect.width() > 0 ) {
7373 metrics.ascent = - sizeRect.height()
7474 metrics.descent = 0
7575
7676 metrics.top = metrics.ascent
7777 metrics.bottom = 0
7878 }
7979
80- return sizeRect.width()
80+ if (sizeRect.width() > 0 ) {
81+ return sizeRect.width()
82+ } else {
83+ // This block of code was added in order to resolve
84+ // span overlap issue on Chromebook devices
85+ // -> https://github.com/wordpress-mobile/AztecEditor-Android/issues/836
86+ return super .getSize(paint, text, start, end, metrics)
87+ }
8188 }
8289
8390 fun adjustBounds (start : Int ): Rect {
@@ -88,8 +95,11 @@ abstract class AztecDynamicImageSpan(val context: Context, protected var imageDr
8895 val layout = textView?.layout
8996
9097 if (measuring || layout == null ) {
91- // if we're in pre-layout phase, just return a tiny rect
92- return Rect (0 , 0 , 1 , 1 )
98+ // if we're in pre-layout phase, just return an empty rect
99+ // Update: Previous version of this code was: return Rect(0, 0, 1, 1)
100+ // but we needed to change it as it caused span overlap issue on Chromebook
101+ // devices -> https://github.com/wordpress-mobile/AztecEditor-Android/issues/836
102+ return Rect (0 , 0 , 0 , 0 )
93103 }
94104
95105 val line = layout.getLineForOffset(start)
@@ -98,7 +108,6 @@ abstract class AztecDynamicImageSpan(val context: Context, protected var imageDr
98108
99109 // use the original bounds if non-zero, otherwise try the intrinsic sizes. If those are not available then
100110 // just assume maximum size.
101-
102111 var width = if ((imageDrawable?.intrinsicWidth ? : - 1 ) > - 1 ) imageDrawable?.intrinsicWidth ? : - 1
103112 else maxWidth
104113 var height = if ((imageDrawable?.intrinsicHeight ? : - 1 ) > - 1 ) imageDrawable?.intrinsicHeight ? : - 1
0 commit comments