Skip to content

Commit 8a0dc05

Browse files
committed
Fix selection after char removal
Generally speaking, removing a char placed just before mask char resulted in misplacement of selection indicator. Consider the setup below: mask: ###-###-### hint: 123456789 Your input: 123456789 Error: Removal of '6' char resulted in selection set after mask, on '7' char instead of '5' char.
1 parent 61370c2 commit 8a0dc05

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

MaskedEditText/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'com.github.dcendents.android-maven'
33

4-
String projectVersion = "1.0.11"
4+
String projectVersion = "1.0.12"
55
String projectGroup = "ru.egslava"
66

77
version = projectVersion

MaskedEditText/src/main/java/br/com/sapereaude/maskedEditText/MaskedEditText.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class MaskedEditText extends AppCompatEditText implements TextWatcher {
4343
private String allowedChars;
4444
private String deniedChars;
4545
private BehaviorProcessor<String> rawTextState = BehaviorProcessor.create();
46-
46+
private boolean blockFurtherSelectionChanges = false;
4747

4848
public MaskedEditText(Context context) {
4949
super(context);
@@ -335,7 +335,7 @@ protected void onSelectionChanged(int selStart, int selEnd) {
335335
// On Android 4+ this method is being called more than 1 time if there is a hint in the EditText, what moves the cursor to left
336336
// Using the boolean var selectionChanged to limit to one execution
337337

338-
if(initialized ){
338+
if(initialized){
339339
if(!selectionChanged) {
340340
selStart = fixSelection(selStart);
341341
selEnd = fixSelection(selEnd);
@@ -350,8 +350,11 @@ protected void onSelectionChanged(int selStart, int selEnd) {
350350

351351
setSelection(selStart, selEnd);
352352
selectionChanged = true;
353-
} else{
354-
//check to see if the current selection is outside the already entered text
353+
blockFurtherSelectionChanges = true;
354+
} else if (blockFurtherSelectionChanges) {
355+
blockFurtherSelectionChanges = false;
356+
} else {
357+
//check to see if the current selection is outside the already entered text
355358
if(selStart > rawText.length() - 1){
356359
final int start = fixSelection(selStart);
357360
final int end = fixSelection(selEnd);

0 commit comments

Comments
 (0)