Skip to content

Commit 62375c6

Browse files
authored
Naive fix for 779 (#1130)
1 parent 9d6b683 commit 62375c6

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

auth/src/main/java/com/firebase/ui/auth/ui/phone/SpacedEditText.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,31 @@ public void setText(CharSequence text, BufferType type) {
6565
*/
6666
@Override
6767
public void setSelection(int index) {
68-
// If the index is the leading edge, there are no spaces before it.
69-
// For all other cases, the index is preceded by index - 1 spaces.
70-
int spacesUpToIndex;
71-
if (index == 0) {
72-
spacesUpToIndex = 0;
73-
} else {
74-
spacesUpToIndex = index - 1;
75-
}
68+
// Desired mapping:
69+
// 0 --> 0
70+
// 1 --> 1
71+
// 2 --> 3
72+
// 3 --> 5
73+
// 4 --> 7
74+
// 5 --> 9
75+
// 6 --> 11
76+
77+
// Naive transformation
78+
int newIndex = (index * 2) - 1;
79+
80+
// Lower bound is 0
81+
newIndex = Math.max(newIndex, 0);
82+
83+
// Upper bound is original length * 2 - 1
84+
newIndex = Math.min(newIndex, (mOriginalText.length() * 2) - 1);
7685

7786
try {
78-
super.setSelection(index + spacesUpToIndex);
87+
super.setSelection(newIndex);
7988
} catch (IndexOutOfBoundsException e) {
80-
// TODO remove once we figure out the bug.
89+
// For debug purposes only
8190
throw new IndexOutOfBoundsException(e.getMessage() +
8291
", requestedIndex=" + index +
83-
", spacesUpToIndex=" + spacesUpToIndex +
92+
", newIndex= " + newIndex +
8493
", originalText=" + mOriginalText);
8594
}
8695
}

0 commit comments

Comments
 (0)