summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-10-22 15:10:28 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-10-22 15:10:28 -0300
commitd8157467bf48e81e91ee360033bd78e938ecec8c (patch)
treec396f6340657bad17bd57ff8ede70332b1f7c291
parentb30083cb385ad5643cf885ed97621b1c39a6d874 (diff)
parent5b4b62c5c99fc8132ead4dd12098fc55e4227520 (diff)
downloadmullvadvpn-d8157467bf48e81e91ee360033bd78e938ecec8c.tar.xz
mullvadvpn-d8157467bf48e81e91ee360033bd78e938ecec8c.zip
Merge branch 'fix-backspaces-in-segmented-input-formatter'
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/util/SegmentedInputFormatter.kt11
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)
+ }
}
}
}