NTP-50225 | Divyesh | offset mapping crash fix (#15529)
Co-authored-by: Mehul Garg <mehul.garg@navi.com>
This commit is contained in:
@@ -654,7 +654,6 @@ class CardNumberVisualTransformation : VisualTransformation {
|
||||
override fun filter(text: AnnotatedString): TransformedText {
|
||||
val transformedTextBuilder = StringBuilder(CARD_NUMBER_MASK)
|
||||
var userInputIndex = 0
|
||||
var cursorPositionIndex = MAX_INDEX_FOR_FIRST_STYLE
|
||||
|
||||
// Replace placeholders with user input
|
||||
for (maskCharIndex in transformedTextBuilder.indices) {
|
||||
@@ -664,7 +663,6 @@ class CardNumberVisualTransformation : VisualTransformation {
|
||||
userInputIndex < MAX_INPUT_LENGTH
|
||||
) {
|
||||
transformedTextBuilder[maskCharIndex] = text[userInputIndex]
|
||||
cursorPositionIndex = maskCharIndex + 1
|
||||
userInputIndex++
|
||||
}
|
||||
}
|
||||
@@ -687,7 +685,12 @@ class CardNumberVisualTransformation : VisualTransformation {
|
||||
val offsetMapping =
|
||||
object : OffsetMapping {
|
||||
override fun originalToTransformed(offset: Int): Int {
|
||||
return cursorPositionIndex.coerceAtMost(CARD_NUMBER_MASK.length)
|
||||
if (offset == 0) {
|
||||
return MAX_INDEX_FOR_FIRST_STYLE
|
||||
}
|
||||
return (2 * offset + MAX_INDEX_FOR_FIRST_STYLE - 1).coerceAtMost(
|
||||
CARD_NUMBER_MASK.length
|
||||
)
|
||||
}
|
||||
|
||||
override fun transformedToOriginal(offset: Int): Int {
|
||||
|
||||
Reference in New Issue
Block a user