Skip to content
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

[TIMOB-25061] Android: Fixed bug where TextField/TextArea setSelection() wrongly triggers a "change" event. #9281

Merged
merged 6 commits into from
Aug 8, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -651,25 +651,25 @@ protected char[] getAcceptedChars()
}

if (d.containsKey(TiC.PROPERTY_INPUT_TYPE)) {
Object obj = d.get(TiC.PROPERTY_INPUT_TYPE);
boolean combineInput = false;
int[] inputTypes = null;
int combinedInputType = 0;

if (obj instanceof Object[]) {
inputTypes = TiConvert.toIntArray((Object[]) obj);
}

if (inputTypes != null) {
combineInput = true;
for (int inputType: inputTypes) {
combinedInputType |= inputType;
}
}

if (combineInput) {
textTypeAndClass = combinedInputType;
}
Object obj = d.get(TiC.PROPERTY_INPUT_TYPE);
boolean combineInput = false;
int[] inputTypes = null;
int combinedInputType = 0;

if (obj instanceof Object[]) {
inputTypes = TiConvert.toIntArray((Object[]) obj);
}

if (inputTypes != null) {
combineInput = true;
for (int inputType: inputTypes) {
combinedInputType |= inputType;
}
}

if (combineInput) {
textTypeAndClass = combinedInputType;
}
}

if (passwordMask) {
Expand Down Expand Up @@ -710,18 +710,29 @@ protected char[] getAcceptedChars()

public void setSelection(int start, int end)
{
// Validate arguments.
int textLength = tv.length();
if (start < 0 || start > textLength || end < 0 || end > textLength) {
Log.w(TAG, "Invalid range for text selection. Ignoring.");
return;
}

// http://stackoverflow.com/a/35527348/1504248
// Do not continue if selection isn't changing. (This is an optimization.)
if ((start == tv.getSelectionStart()) && (end == tv.getSelectionEnd())) {
return;
}

// This works-around an Android 4.x bug where the "end" index will be ignored
// if setSelection() is called just after tapping the text field. (See: TIMOB-19639)
Editable text = tv.getText();
if (text.length() > 0) {
boolean wasDisabled = this.disableChangeEvent;
this.disableChangeEvent = true;
text.replace(0, 1, text.subSequence(0, 1), 0, 1);
this.disableChangeEvent = wasDisabled;
}


// Change the cursor position and text selection.
tv.setSelection(start, end);
}

Expand Down