wordpress-mobile / AztecEditor-Android

A reusable native Android rich text editor component.
Mozilla Public License 2.0
693 stars 115 forks source link

Crash: Tapping More and Page Buttons When Selecting Text Backwards with Keyboard #361

Closed theck13 closed 7 years ago

theck13 commented 7 years ago

Expected

Tapping the More or Page format button will replace the selected text with the <!--more--> or <!--nextpage--> for any selected text.

Observed

Tapping More or Page format button crashes the app when the selecting text backwards with a keyboard. See the stack trace below for details.

06-06 10:32:32.135 2688-2688/org.wordpress.aztec E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.wordpress.aztec, PID: 7032
    java.lang.IndexOutOfBoundsException: replace (4 ... 0) has end before start
        at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1258)
        at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:515)
        at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:509)
        at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:508)
        at org.wordpress.aztec.formatting.LineBlockFormatter.applyComment(LineBlockFormatter.kt:115)
        at org.wordpress.aztec.formatting.LineBlockFormatter.applyPageComment(LineBlockFormatter.kt:23)
        at org.wordpress.aztec.AztecText.toggleFormatting(AztecText.kt:567)
        at org.wordpress.aztec.toolbar.AztecToolbar.onToolbarAction(AztecToolbar.kt:335)
        at org.wordpress.aztec.toolbar.AztecToolbar.access$onToolbarAction(AztecToolbar.kt:23)
        at org.wordpress.aztec.toolbar.AztecToolbar$initView$1.onClick(AztecToolbar.kt:269)
        at android.view.View.performClick(View.java:5637)
        at android.widget.CompoundButton.performClick(CompoundButton.java:122)
        at android.view.View$PerformClick.run(View.java:22429)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Reproduced

  1. Enter "this" text.
  2. Place cursor after "s" in "this" text.
  3. Hold Shift key and tap Left Arrow key four times.
  4. Tap More or Page format button.

Tested

Google Pixel on Android 7.1.2 with AztecDemo 1.0

khaykov commented 7 years ago

Can't reproduce this one anymore, so closing for now.