-
-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(android/engine): Skip updating selection range if invalid #11384
Conversation
User Test ResultsTest specification and instructions
Test Artifacts |
int selStart = icText.selectionStart; | ||
int selEnd = icText.selectionEnd; | ||
|
||
if (selStart < 0 || selEnd < 0) { | ||
// There is no selection or cursor | ||
// Reference https://developer.android.com/reference/android/text/Selection#getSelectionEnd(java.lang.CharSequence) | ||
return false; | ||
} | ||
|
||
int selMin = selStart, selMax = selEnd; |
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.
Personally, I'd like to eliminate the selStart
and selEnd
variables. They just add potential for error.
int selStart = icText.selectionStart; | |
int selEnd = icText.selectionEnd; | |
if (selStart < 0 || selEnd < 0) { | |
// There is no selection or cursor | |
// Reference https://developer.android.com/reference/android/text/Selection#getSelectionEnd(java.lang.CharSequence) | |
return false; | |
} | |
int selMin = selStart, selMax = selEnd; | |
int selMin = icText.selectionStart, selMax = icText.selectionEnd; | |
if (selMin < 0 || selMax < 0) { | |
// There is no selection or cursor | |
// Reference https://developer.android.com/reference/android/text/Selection#getSelectionEnd(java.lang.CharSequence) | |
return false; | |
} | |
if(selMin > selMax) { | |
selMin = icText.selectionEnd; | |
selMax = icText.selectionStart; | |
} |
I can't do this suggestion across the whole range of this code, so you'll need to delete the subsequent if clause.
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.
Similarly, we should eliminate the result
variable, and short-circuit the input conditions:
InputConnection ic = KMManager.getInputConnection(this.keyboardType);
if (ic == null) {
// TODO: please explain
return true;
}
ExtractedText icText = ic.getExtractedText(new ExtractedTextRequest(), 0);
if (icText == null) {
// TODO: please explain
return false;
}
// ... the rest of the function goes here ...
return true;
Why do we return true when ic == null?
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.
Refactoring addressed in #11389. Also fixes to return false if ic == null.
Test Results
Note: The reverse text selection does not happen from one point to another. It's restricted to the last letter of the word. I observed this behavior in Android 13 (Physical Device) and emulator devices in Android 9 and 12 versions. |
Changes in this pull request will be available for download in Keyman version 17.0.321-beta |
Fixes #11360
@mcdurdin went spelunking in the Android code and found
getSelectionStart()
andgetSelectionEnd()
return -1 if there's no selection or cursor.Reference https://developer.android.com/reference/android/text/Selection#getSelectionEnd(java.lang.CharSequence
In those cases (likely a race condition), we should no-op on
updateSelectionRange()
since there's no valid selection to pass to KeymanWeb.User Testing (from #11360)
Setup - Install PR build of Keyman for Android and enable Keyman as the default system keyboard