Skip to content

Commit 109b896

Browse files
authored
Merge pull request #402 from wordpress-mobile/issue/396-fixing-image-click-detection
Issue/396 fixing image click detection
2 parents c9b96b9 + d56dbc0 commit 109b896

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/EnhancedMovementMethod.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.wordpress.aztec
22

33
import android.graphics.Rect
4-
import android.text.Selection
54
import android.text.Spannable
65
import android.text.method.ArrowKeyMovementMethod
76
import android.text.style.ClickableSpan
@@ -29,7 +28,11 @@ object EnhancedMovementMethod : ArrowKeyMovementMethod() {
2928

3029
val layout = widget.layout
3130
val line = layout.getLineForVertical(y)
32-
val off = layout.getOffsetForHorizontal(line, x.toFloat())
31+
var off = layout.getOffsetForHorizontal(line, x.toFloat())
32+
33+
if (text.length > off) {
34+
off++
35+
}
3336

3437
// get the character's position. This may be the left or the right edge of the character so, find the
3538
// other edge by inspecting nearby characters (if they exist)
@@ -40,18 +43,15 @@ object EnhancedMovementMethod : ArrowKeyMovementMethod() {
4043
val lineRect = Rect()
4144
layout.getLineBounds(line, lineRect)
4245

43-
if (((x >= charPrevX && x <= charX) || (x >= charX && x <= charNextX))
46+
if (((x in charPrevX..charX) || (x in charX..charNextX))
4447
&& y >= lineRect.top && y <= lineRect.bottom) {
4548
val link = text.getSpans(off, off, ClickableSpan::class.java).firstOrNull()
4649

4750
// Only react to AztecMediaClickableSpan and UnknownClickableSpan; not to regular links.
4851
if (link != null && (link is AztecMediaClickableSpan || link is UnknownClickableSpan)) {
4952
if (action == MotionEvent.ACTION_UP) {
5053
link.onClick(widget)
51-
} else {
52-
Selection.setSelection(text, text.getSpanStart(link), text.getSpanEnd(link))
5354
}
54-
5555
return true
5656
}
5757
}

0 commit comments

Comments
 (0)