Skip to content

Conversation

@planarvoid
Copy link
Contributor

Fix

In this PR I've added support for indent and outdent for headings, preformat, quotes and paragraphs (as well as text without any spans). The logic adds a \t element at the beginning of each selected line on indent and removes the \t if present on outdent.

Test

  1. Make sure you add the indent and outdent toolbar actions in MainActivity
  2. Run the app
  3. Try indenting/outdenting everything including selection over multiple items
  4. Notice the selection is moving correctly when indenting/outdenting
  5. Notice the indent/outdent buttons are enabled when they should be

Review

@AmandaRiu

Make sure strings will be translated:

  • If there are new strings that have to be translated, I have added them to the client's strings.xml as a part of the integration PR.

@planarvoid planarvoid requested a review from AmandaRiu April 15, 2022 14:19
@planarvoid planarvoid self-assigned this Apr 15, 2022
Copy link
Contributor

@AmandaRiu AmandaRiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@planarvoid Testing with the Example text prepopulated seems to work fine, but when starting with an empty editor I ran into a bunch of issues:

Odd behavior after indenting list items where the indent/outdent buttons will randomly not be available. See video:

issue-indent-disabled.mov

Crash just trying to type into the editor outside of a block. I can also add a list and type just fine and then add some space after the list and attempt to type or indent/outdent and get the same type of crash:

issue-text-block.mov

Here’s the stacktrace:

2022-04-15 14:07:19.488 18426-18426/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.wordpress.aztec, PID: 18426
    java.lang.IndexOutOfBoundsException: charAt: 25 >= length 25
        at android.text.SpannableStringBuilder.charAt(SpannableStringBuilder.java:125)
        at org.wordpress.aztec.formatting.IndentFormatter.selectionCanBeOutdented(IndentFormatter.kt:139)
        at org.wordpress.aztec.formatting.IndentFormatter.isOutdentAvailable(IndentFormatter.kt:177)
        at org.wordpress.aztec.formatting.BlockFormatter.isOutdentAvailable(BlockFormatter.kt:85)
        at org.wordpress.aztec.AztecText.isOutdentAvailable(AztecText.kt:977)
        at org.wordpress.aztec.toolbar.AztecToolbar.setIndentState(AztecToolbar.kt:549)
        at org.wordpress.aztec.toolbar.AztecToolbar.highlightAppliedStyles(AztecToolbar.kt:541)
        at org.wordpress.aztec.toolbar.AztecToolbar.access$highlightAppliedStyles(AztecToolbar.kt:46)
        at org.wordpress.aztec.toolbar.AztecToolbar$setEditor$1.onSelectionChanged(AztecToolbar.kt:410)
        at org.wordpress.aztec.AztecText.onSelectionChanged(AztecText.kt:1081)
        at android.widget.TextView.spanChange(TextView.java:10963)
        at android.widget.TextView$ChangeWatcher.onSpanChanged(TextView.java:13832)
        at android.text.SpannableStringBuilder.sendSpanChanged(SpannableStringBuilder.java:1308)
        at android.text.SpannableStringBuilder.sendToSpanWatchers(SpannableStringBuilder.java:652)
        at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:581)
        at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:508)
        at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:38)
        at org.wordpress.aztec.formatting.IndentFormatter.outdent(IndentFormatter.kt:104)
        at org.wordpress.aztec.formatting.BlockFormatter.outdent(BlockFormatter.kt:75)
        at org.wordpress.aztec.AztecText.outdent(AztecText.kt:968)
        at org.wordpress.aztec.toolbar.AztecToolbar.onToolbarAction(AztecToolbar.kt:642)
        at org.wordpress.aztec.toolbar.AztecToolbar.access$onToolbarAction(AztecToolbar.kt:46)
        at org.wordpress.aztec.toolbar.AztecToolbar$setupToolbarItems$$inlined$let$lambda$1.onClick(AztecToolbar.kt:783)
        at android.view.View.performClick(View.java:7441)
        at android.widget.CompoundButton.performClick(CompoundButton.java:146)
        at android.view.View.performClickInternal(View.java:7418)
        at android.view.View.access$3700(View.java:835)
        at android.view.View$PerformClick.run(View.java:28676)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7839)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

The outdent option is available even if there is nothing indented:

issue-outdent-enabled

Base automatically changed from feature/item-indent to trunk April 20, 2022 20:35
@planarvoid planarvoid changed the base branch from trunk to feature/enable-combined-lists May 5, 2022 07:24
@planarvoid
Copy link
Contributor Author

thanks for the review @AmandaRiu ! Good catches!

Odd behavior after indenting list items where the indent/outdent buttons will randomly not be available. See video:

this was fixed in another PR so I've pointed this PR to the feature/enable-combined-lists branch and it works now

Crash just trying to type into the editor outside of a block. I can also add a list and type just fine and then add some space after the list and attempt to type or indent/outdent and get the same type of crash:

This should be fixed now. I've added checks around empty strings for indent and outdent and added tests around this behaviour

@planarvoid planarvoid requested a review from AmandaRiu May 5, 2022 07:54
Copy link
Contributor

@AmandaRiu AmandaRiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works beautifully @planarvoid ! The same issue I found in the other PR with the ANR happens in this one as well but that's to be expected and can be fixed in that parent branch. LGTM!! :shipit:

@AmandaRiu AmandaRiu merged commit 9773da7 into feature/enable-combined-lists May 11, 2022
@AmandaRiu AmandaRiu deleted the feature/indent-outdent-other-items branch May 11, 2022 02:38
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

Successfully merging this pull request may close these issues.

3 participants