diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index 0479f817..bebeec13 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -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) - } -} diff --git a/VDS/Components/TextFields/InputField/TextField.swift b/VDS/Components/TextFields/InputField/TextField.swift index 9a96829e..933b8f47 100644 --- a/VDS/Components/TextFields/InputField/TextField.swift +++ b/VDS/Components/TextFields/InputField/TextField.swift @@ -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) + } +}