Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on link click if text is selectable #11

Closed
pchupik opened this issue Oct 26, 2017 · 4 comments
Closed

Crash on link click if text is selectable #11

pchupik opened this issue Oct 26, 2017 · 4 comments

Comments

@pchupik
Copy link

pchupik commented Oct 26, 2017

In sample app make the textView text-selectable (e.g. by adding android:textIsSelectable="true")

  1. Select some text in the textView which contains clickableSpan
  2. Click on the clickableSpan
    crash.txt
java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts before 0
...
at me.saket.bettermovementmethod.BetterLinkMovementMethod.highlightUrl(BetterLinkMovementMethod.java:342)
at me.saket.bettermovementmethod.BetterLinkMovementMethod.onTouchEvent(BetterLinkMovementMethod.java:222)
@saket
Copy link
Owner

saket commented Oct 28, 2017

Hey @pchupik, I'm busy traveling till 10th of Nov and so won't be able to look into this until then. :(

@pchupik
Copy link
Author

pchupik commented Oct 31, 2017

Looks like I found a fix for this. In BetterLinkMovementMethod.highlightUrl( ) add check textView for selection and clear focus if it has one:

text.setSpan(new BackgroundColorSpan(textView.getHighlightColor()), spanStart, spanEnd, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
if (textView.hasSelection())
           textView.clearFocus();
textView.setText(text);

@saket
Copy link
Owner

saket commented Feb 18, 2018

Fixed in commit d0a7db1. Will release a new version soon. In the meanwhile, you can get a build off HEAD using jitpack.io.

@saket
Copy link
Owner

saket commented Feb 18, 2018

Fixed in 2.1.0: https://github.com/Saketme/Better-Link-Movement-Method/releases/tag/v2.1.0

@saket saket closed this as completed Feb 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants