From bb9c5b7ba8c0763b8cbf3b20a528beb4ca09c6ed Mon Sep 17 00:00:00 2001 From: Christoffer Winterkvist Date: Fri, 20 Nov 2015 12:25:27 +0100 Subject: [PATCH] Fix jumpy cursor --- Demo copy.xcworkspace/contents.xcworkspacedata | 10 ++++++++++ Source/Cells/Views/FORMTextField.m | 13 ++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 Demo copy.xcworkspace/contents.xcworkspacedata diff --git a/Demo copy.xcworkspace/contents.xcworkspacedata b/Demo copy.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..1f140198 --- /dev/null +++ b/Demo copy.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/Source/Cells/Views/FORMTextField.m b/Source/Cells/Views/FORMTextField.m index 70eab15d..168de65c 100755 --- a/Source/Cells/Views/FORMTextField.m +++ b/Source/Cells/Views/FORMTextField.m @@ -118,11 +118,18 @@ - (void)setText:(NSString *)text { BOOL didFormat = (text.length > super.text.length); BOOL cursorAtEnd = (newRawText.length == range.location); + [super setText:text]; if ((didAddText && didFormat) || (didAddText && cursorAtEnd)) { - self.selectedTextRange = textRange; - [super setText:text]; + if (range.location < text.length) { + UITextPosition *start = [self positionFromPosition:self.beginningOfDocument + offset:range.location + 1]; + UITextPosition *end = [self positionFromPosition:start + offset:range.length]; + UITextRange *newTextRange = [self textRangeFromPosition:start + toPosition:end]; + self.selectedTextRange = newTextRange; + } } else { - [super setText:text]; self.selectedTextRange = textRange; } }