Skip to content

Commit b172b34

Browse files
committed
Fix incorrect cursor position after replace a text range
1 parent 0773d43 commit b172b34

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

FormattedTextField/FormattedTextField.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ open class FormattedTextField: UITextField {
200200

201201
unformattedText.replaceSubrange(unformattedText.range(fromNsRange: unformattedRange)!, with: string)
202202
cursorPosition += string.characters.count
203+
if string.characters.count > 0 {
204+
cursorPosition -= unformattedRange.length
205+
}
203206

204207
let newFormattedText = self.formattedText(fromText: unformattedText, textMask: textMask, cursorPosition: &cursorPosition)
205208
text = newFormattedText

0 commit comments

Comments
 (0)