moved extension
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
4ed2b3c894
commit
a71e391050
@ -348,26 +348,3 @@ extension String {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension UITextField {
|
||||
internal func cursorPosition(range: NSRange, replacementString string: String, rawNumber: String, formattedNumber: String) -> UITextPosition? {
|
||||
let start = range.location
|
||||
let length = string.count
|
||||
|
||||
let newCursorLocation = start + length
|
||||
|
||||
// Adjust the cursor position to skip over formatting characters
|
||||
var formattedCharacterCount = 0
|
||||
for (index, character) in formattedNumber.enumerated() {
|
||||
if index >= newCursorLocation + formattedCharacterCount {
|
||||
break
|
||||
}
|
||||
if !character.isNumber {
|
||||
formattedCharacterCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
let finalCursorLocation = min(newCursorLocation + formattedCharacterCount, formattedNumber.count)
|
||||
return position(from: beginningOfDocument, offset: finalCursorLocation)
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,3 +82,26 @@ open class TextField: UITextField {
|
||||
return success
|
||||
}
|
||||
}
|
||||
|
||||
extension UITextField {
|
||||
public func cursorPosition(range: NSRange, replacementString string: String, rawNumber: String, formattedNumber: String) -> UITextPosition? {
|
||||
let start = range.location
|
||||
let length = string.count
|
||||
|
||||
let newCursorLocation = start + length
|
||||
|
||||
// Adjust the cursor position to skip over formatting characters
|
||||
var formattedCharacterCount = 0
|
||||
for (index, character) in formattedNumber.enumerated() {
|
||||
if index >= newCursorLocation + formattedCharacterCount {
|
||||
break
|
||||
}
|
||||
if !character.isNumber {
|
||||
formattedCharacterCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
let finalCursorLocation = min(newCursorLocation + formattedCharacterCount, formattedNumber.count)
|
||||
return position(from: beginningOfDocument, offset: finalCursorLocation)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user