wordpress-mobile / AztecEditor-Android

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

Issue/880 center point not in rectangle #1044

Closed nbradbury closed 1 year ago

nbradbury commented 1 year ago

Fixes #880

We have 37 Sentry users experiencing the "IllegalArgumentException: Center point is not inside any of the rectangles" crash in Day One, all of which are on Android 13 (Tiramisu). This appears to be a platform issue rather than a problem with Aztec itself.

Update: It turns out the crash isn't limited to Android 13.

This PR resolves the problem by detecting and ignoring that crash on Android 13. I'm not well-versed with the Aztec codebase, so if there's a better way to resolve this please let me know.

To test:

cameocoder commented 1 year ago

This issue is not limited to TIRAMISU.

It happens when you "Select All" and the editor just contains empty spans. Spans that are started but do not actually contain any text/content.

Another way to reproduce the crash is to start the example app with a blank editor (no EXAMPLE text)

  1. Start an ordered/unordered list
  2. Select All

The reason it is reproducible from the example app when you clear the Example text may be because there are a number of empty spans that are left behind after trying to clear the text. In particular many AztecVisualLinebreak spans left behind which is a separate issue.

My guess is that the fix for this may be in handling onTextContextMenuItem and Aztec may need to implement its own selectAllText similar to how it custom handles cut/copy/paste. This may also fix the issue of spans being left behind when you select all of the EXAMPLE text and delete it.

nbradbury commented 1 year ago

This issue is not limited to TIRAMISU.

@cameocoder Thanks for the clarification! I've removed the version check in 690ae78. I'm not well-versed with this codebase, so I'll wait for someone on the team to chime in about other solutions.

khaykov commented 1 year ago

While the fix prevents the crash, if you start typing after selecting empty span, the app will hang :) Ideally we do not want to show the context menu when there is only empty span in editor, but I'm not sure we can do it on the library level.

As @cameocoder suggested, we can a add a bit of logic to onTextContextMenuItem to deal with it. I think not selecting anything when there is only a block span in editor is a valid option.

Something like this should handle it (have not tested it extensively):

android.R.id.selectAll -> {
                return if (text.toString() == Constants.END_OF_BUFFER_MARKER.toString()) {
                    deleteInlineStyleFromTheBeginning()
                    return true
                } else {
                    super.onTextContextMenuItem(id)
                }
            }
nbradbury commented 1 year ago

@khaykov Thanks for the assist! I made the changes you suggested.