diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-10-21 15:05:21 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-10-22 17:36:55 +0000 |
| commit | 5b4b62c5c99fc8132ead4dd12098fc55e4227520 (patch) | |
| tree | c396f6340657bad17bd57ff8ede70332b1f7c291 /android | |
| parent | b30083cb385ad5643cf885ed97621b1c39a6d874 (diff) | |
| download | mullvadvpn-5b4b62c5c99fc8132ead4dd12098fc55e4227520.tar.xz mullvadvpn-5b4b62c5c99fc8132ead4dd12098fc55e4227520.zip | |
Remove trailing separator after updating selection
Diffstat (limited to 'android')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/util/SegmentedInputFormatter.kt | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/util/SegmentedInputFormatter.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/util/SegmentedInputFormatter.kt index 0f7db7f1c8..9154f102ef 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/util/SegmentedInputFormatter.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/util/SegmentedInputFormatter.kt @@ -36,13 +36,13 @@ class SegmentedInputFormatter(val input: EditText, var separator: Char) : TextWa if (isValidInput(string)) { editing = false - maybeUpdateSelection() + maybeUpdateSelection(text) } else { formatInput(text) } } - private fun maybeUpdateSelection() { + private fun maybeUpdateSelection(text: Editable) { if (removing) { var start = input.selectionStart var end = input.selectionEnd @@ -60,6 +60,13 @@ class SegmentedInputFormatter(val input: EditText, var separator: Char) : TextWa if (changed) { input.setSelection(start, end) + + if (start == end && end == text.length - 1) { + // The cursor was previously at the last character, and now after the character + // was removed it has been moved to before the separator. It's best now to + // remove the unnecessary trailing separator + text.delete(text.length - 1, text.length) + } } } } |
