Skip to content

Commit 4cf369d

Browse files
author
Steve Hannah
committed
fix: [3851] fixed iOS losing cursor position when using predictive text
Fixes #3851
1 parent 957aa8b commit 4cf369d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Ports/iOSPort/nativeSources/IOSNative.m

+11-1
Original file line numberDiff line numberDiff line change
@@ -7610,7 +7610,17 @@ void com_codename1_impl_ios_IOSNative_updateNativeEditorText___java_lang_String(
76107610
NSString* nsText = toNSString(CN1_THREAD_GET_STATE_PASS_ARG text);
76117611
NSString* currText = ((UITextView*)editingComponent).text;
76127612
if (![nsText isEqualToString:currText]) {
7613-
((UITextView*)editingComponent).text = nsText;
7613+
UITextView *textView = (UITextView *)editingComponent;
7614+
7615+
// Save current cursor position
7616+
NSRange selectedRange = textView.selectedRange;
7617+
7618+
// Update the text
7619+
textView.text = nsText;
7620+
7621+
// Restore the cursor position
7622+
NSUInteger newPosition = MIN(selectedRange.location, textView.text.length);
7623+
textView.selectedRange = NSMakeRange(newPosition, 0);
76147624
}
76157625
}
76167626
POOL_END();

0 commit comments

Comments
 (0)