-
Notifications
You must be signed in to change notification settings - Fork 26
[Android] Fix using emojis inside composing regions #883
[Android] Fix using emojis inside composing regions #883
Conversation
This should also prevent some invalid indexes from being sent to the RTE library when modifying the `Editable`.
FWIW, I've also tested this with CJK languages and it works as expected, so I'm not sure why the previous behaviour was decided long ago. |
Kudos, SonarCloud Quality Gate passed! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #883 +/- ##
============================================
- Coverage 87.44% 87.28% -0.16%
Complexity 407 407
============================================
Files 165 133 -32
Lines 18964 17364 -1600
Branches 1048 405 -643
============================================
- Hits 16583 15157 -1426
+ Misses 2086 1936 -150
+ Partials 295 271 -24
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
The exception is from Rust:
Do you think it could be an issue with indexing? Perhaps something similar to #824 i.e. not taking account of code points vs code units? |
The error comes from Rust, but it's because the I think it's normal that Rust throws an error in this case, that index shouldn't have been sent to it in the first place. |
We could try to solve this in Rust instead, or add some extra protection against it. But assuming the same example as above with |
I see what you mean... it looks like the EditText is working in code units as we see by manually moving the cursor from But if we insert I'm wondering if there is a missing a piece inside our input connection which is causing |
I was talking about The new position seems to be calculated there as: newCursorPosition = newCursorPosition + start In our case, we always pass After looking at the code again, it seems to be setting whatever is on However, I don't think doing this is needed at all. We're actually replacing the whole contents of the Editable with each change in the RTE, so doing |
I think it's this code that's causing the selection change, the 2nd if, probably: https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/text/SpannableStringBuilder.java;l=552?q=SpannableStringBuilder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested and there is no issue with the flickering suggestion indicator (when using a soft keyboard). And given the text watcher issue fixed in #248 has not resurfaced, I don't see any issues with this change.
Thanks for fixing the issue!
@@ -333,7 +333,8 @@ internal class InterceptInputConnection( | |||
|
|||
private fun replaceAll(charSequence: CharSequence) { | |||
editable.removeFormattingSpans() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still necessary now we are clearing the editable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not, I'll double check just in case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a crash when testing the RTE that happened when I added an emoji in the middle of a word, the composer suddenly got an invalid index in the middle of the emoji and it crashes.
It turns out it comes from
replaceAll
doingeditable.replace(0, editable.length, someOtherValue)
. To test this, I:Test
in the composer.Te|st
).editable.replace(0, editable.length, ...)
insidereplaceAll
, the selection is at 2, but after that it's automatically moved to 3 by no code of ours, something inside Android must be doing it.The behavior of
replaceAll
was done like that to prevent the suggestion from flashing when typing, but I just now tried to do:And the issue is fixed and the suggestions still work as expected. Moreover, we're not sending invalid indexes anymore to the composer, which seems like an unexpected win.
I had to change the order of the expected results of
dumpSpans()
since the new spans are not added at the end now, but at position1
.