TP-59496 fix index out of bound exception in number comma transformation (#383)
This commit is contained in:
@@ -11,6 +11,7 @@ import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.input.OffsetMapping
|
||||
import androidx.compose.ui.text.input.TransformedText
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import com.navi.uitron.utils.EMPTY
|
||||
import com.navi.uitron.utils.toDoubleWithSafe
|
||||
|
||||
class NumberCommaTransformation : VisualTransformation {
|
||||
@@ -19,14 +20,18 @@ class NumberCommaTransformation : VisualTransformation {
|
||||
val transformation = reformat(text.text)
|
||||
|
||||
return TransformedText(
|
||||
AnnotatedString(transformation.formatted ?: ""),
|
||||
AnnotatedString(transformation.formatted ?: EMPTY),
|
||||
object : OffsetMapping {
|
||||
override fun originalToTransformed(offset: Int): Int {
|
||||
return transformation.originalToTransformed[offset]
|
||||
return transformation.originalToTransformed.getOrNull(offset)
|
||||
?: transformation.formatted?.length
|
||||
?: 0
|
||||
}
|
||||
|
||||
override fun transformedToOriginal(offset: Int): Int {
|
||||
return transformation.transformedToOriginal[offset]
|
||||
return transformation.transformedToOriginal.getOrNull(offset)
|
||||
?: transformation.formatted?.length
|
||||
?: 0
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user