Wrong caret calculation in SumTextInputFormatter
Closed this issue · 1 comments
snowtema commented
In my app pattern for SumTextInputFormatter
calculates by this small hack:
let f = NumberFormatter()
f.numberStyle = .currency
let source = f.string(from: NSNumber(value: 1234.56))
guard let pattern = source?.replacingOccurrences(of: "[0-9]", with: "#", options: .regularExpression) else {
return
}
formatter = SumTextInputFormatter(textPattern: pattern)
So, for Russian locale on the device pattern will be # ###,## ₽
and for English locale, it will be $#,###.##
. This hack adopts my app for multiple locales and ICU CLDR.
And here we are. The problem occurred when we use Russian locale and trying to delete characters with an amount greater than 1000 (In this case text formats with grouping symbol with space, like a "1 220"). When amount less than 1000 or locale is English – everything works fine.
Deleted user commented
Probably, it happened because there is a collision with group separator (space) and suffix (space + currency sign) for Ru locale