Closed rocka closed 2 years ago
Thank you @rocka for your contribution! This repository was migrated to https://github.com/mozilla-mobile/firefox-android and you'd have to clone the new repo and manually re-apply your changes to continue. Sorry for the inconvenience.
This PR fix 2 issues in InlineAutocompleteEditText:
Modern input methods tend to use InputConnection APIs rather than sending keycode to simulate keypress. Override method InputConnection#deleteSurroundingTextInCodePoints(int,int) available on API level 24+ to unify the behavior.
https://user-images.githubusercontent.com/13914967/197770365-8b3e81a1-9353-4482-9257-7a0ff67e3d8d.mp4
As the video above indicates, input state desyncs between Editor and IME when press Backspace while there is unfinished composing text.
To explain the behavior step by step:
redd
in address bar, IME presents composing textredd
, and Inline AutocompleteEditText completes toredd|it.com
red
. But AutocompleteEditText ignores the request, finishing composing textredd
insteadre
. But composing range was lost because AutocompleteEditText has finished composing already, causing IME set composing text after finished textredd
Looking through
setComposingText
implementation, it always callremoveAutocompleteOnComposing
first.https://github.com/mozilla-mobile/android-components/blob/bd1adfd687aa496f2bd4805816553241126c32c9/components/ui/autocomplete/src/main/java/mozilla/components/ui/autocomplete/InlineAutocompleteEditText.kt#L602-L611
In
removeAutocompleteOnComposing
, when incoming text shorter than existing composing text, it callsfinishingComposingText()
and drops incoming text. Althrough the comment says "having finishComposingText() send change notifications to the IME", but there is NO API for IME to know that composing text has been changed, which is the cause of state desync.https://github.com/mozilla-mobile/android-components/blob/bd1adfd687aa496f2bd4805816553241126c32c9/components/ui/autocomplete/src/main/java/mozilla/components/ui/autocomplete/InlineAutocompleteEditText.kt#L575-L592
This PR changes
finishingComposingText()
torestartInput()
, so IME can know previous InputConnection has been interrupted, allowing IME to reset it's internal state.After the change, if IME is capable of providing text correction based on surrounding text, it can show candidate words as usual. Otherwise (as the video above), composing range in InlineAutocompleteEditText and IME are both cleared, no desync would occur.
possible related issues:
PS: it would be nice if there are some documentation mentions that you need
AppCompat
Theme to makeInlineAutocompleteEditText
work correctly. I spent hours on setting up development environment and test project for this.Pull Request checklist
After merge
GitHub Automation
Used by GitHub Actions.