Closed 0nko closed 5 years ago
Found this only happens if you follow the steps above by the letter. But, if you position the cursor somewhere in the body first (by tapping before/after anything in the content area), then tapping on one of the special comments action icons works alright, inserting the desired object on the desired position.
More info on this: this only happens if the cursor is at the very beginning of the content: tapping at the left of the first image in the Aztec demo app shows the cursor blinking, and then trying to insert something there (more, page OR horizontal ruler) makes it fail
Confirming this happens since API 26 as well (Android 8.0.0)
Managed to narrow this down to:
For example, in the demo app, trying to insert a Horizontal Rule right before the following content produces the crash:
"[caption]<img src=\"https://examplebloge.files.wordpress.com/2017/02/3def4804-d9b5-11e6-88e6-d7d8864392e0.png\" />ExampleCaption[/caption]"
However, this other content does not produce the crash (it's just the same as above without the ExampleCaption
text, and more specifically without any caption text, even when the [caption]
tag is present):
"[caption]<img src=\"https://examplebloge.files.wordpress.com/2017/02/3def4804-d9b5-11e6-88e6-d7d8864392e0.png\" />[/caption]"
Still trying to gather information to see what relates [caption]
with how the horizontal rule / special comments are related.
I also managed to make it crash with the very/similar output when inserting ANY character right before the captioned image, although I believe this might be a different problem (the cause certainly looks different, although the crash is the same):
Apparently, checking the code I can avoid this crash from happening when commenting out the following piece of code, which was introduced in commit https://github.com/wordpress-mobile/AztecEditor-Android/commit/668dcfb078b924cfaeb88bbaa775311d4b9e9a49 :
If you comment out those lines, following the above steps 1-4 donโt make it crash. @0nko do you see anything here that might be a root/shared cause?
I've played around with the app and I can confirm what you mentioned above. Setting the HTML to the following will always crash:
[caption align="alignright"]<img src="https://examplebloge.files.wordpress.com/2017/02/3def4804-d9b5-11e6-88e6-d7d8864392e0.png">Caption[/caption]
Apparently, checking the code I can avoid this crash from happening when commenting out the following piece of code, which was introduced in commit 668dcfb
The code above is just one of many manifestations of the same error and it's not limited to CaptionWatcher
. It appears that in specific situations setSpan()
throws that exception but it doesn't in others. For the example above, adding a character before an image calls setSpan(<caption_span>, 1, span.end, span.flags)
. If I changed the start position to 0 it would not crash, however. Also changing the span to an inline span also works even with the original bounds.
I tried a couple of things, like removing some other spans, removing and then setting the caption span but nothing worked. The only thing that did work was setting a span on a separate Editable
, like this:
val t = aztecText.text
t.setSpan(...)
aztecText.text = t
It could probably work for the other case with the special comment, we'd just need to find the specific call to setSpan()
.
Nice find @0nko ! I'm surprised that val t = aztecText.text
produces a different Editable (I would have thought it's the same reference). Will try for both cases and come back here ๐
I've discovered a curious situation. Try the following:
a[caption align="alignright"]<img src="https://examplebloge.files.wordpress.com/2017/02/3def4804-d9b5-11e6-88e6-d7d8864392e0.png">Caption[/caption]
a
so that the image is on the first linea
right in front of the image => WORKSa
a
right in front of the image => CRASHWeird eh? It seems the caption at the very beginning puts AztecText
into a bad state.
Weird eh? It seems the caption at the very beginning puts AztecText into a bad state.
It is! I tend to think something is just not rightly handled with spans in the platform. Anyway, just tested on the PR branch and couldn't repro :+1:
There's even more weird stuff
Paste that same thing in the source editor
a[caption align="alignright"]<img src="https://examplebloge.files.wordpress.com/2017/02/3def4804-d9b5-11e6-88e6-d7d8864392e0.png">Caption[/caption]
Switch to visual
Put the cursor right after the "a" and hit backspace
Switch to HTML mode, see this is the content now:
<br> [caption align="alignright"]<img src="https://examplebloge.files.wordpress.com/2017/02/3def4804-d9b5-11e6-88e6-d7d8864392e0.png">Caption[/caption]
(Look at the <br>
up there)
Switch to visual mode
Place the cursor right to the left of the image and hit backspace, see the whole content moves up one line
Switch to HTML
Observe not only the br
is gone, but also the [caption]
tag is gone as well, leaving an unformatted "Caption" text:
<br> [caption align="alignright"]<img src="https://examplebloge.files.wordpress.com/2017/02/3def4804-d9b5-11e6-88e6-d7d8864392e0.png">Caption[/caption]
Also the undo/redo does weird stuff
Sorry this is the content observed in step 8 above:
<img src="https://examplebloge.files.wordpress.com/2017/02/3def4804-d9b5-11e6-88e6-d7d8864392e0.png">Caption
Tracked by Google here: https://issuetracker.google.com/issues/67102093
Great - I think we may even get away without "fixing" (hacking around) it.
Decision: we have to catch the global exception and try to recover from the crash, if it's possible at all.
It has been fixed by Google. It will be released in the next Android version ๐.
It has been fixed by Google. It will be released in the next Android version ๐
niiiiiiiceeee ๐ ๐
Fixed for now I Android 8.x via #801, closing
Applying a special comment (more, page) results in a crash on Oreo 8.1 (API 27)
Reproduced
Tested
Emulator running API 27.