Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [3851] fixed iOS losing cursor position when using predictive text #3875

Merged
merged 1 commit into from
Feb 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Ports/iOSPort/nativeSources/IOSNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -7610,7 +7610,17 @@ void com_codename1_impl_ios_IOSNative_updateNativeEditorText___java_lang_String(
NSString* nsText = toNSString(CN1_THREAD_GET_STATE_PASS_ARG text);
NSString* currText = ((UITextView*)editingComponent).text;
if (![nsText isEqualToString:currText]) {
((UITextView*)editingComponent).text = nsText;
UITextView *textView = (UITextView *)editingComponent;

// Save current cursor position
NSRange selectedRange = textView.selectedRange;

// Update the text
textView.text = nsText;

// Restore the cursor position
NSUInteger newPosition = MIN(selectedRange.location, textView.text.length);
textView.selectedRange = NSMakeRange(newPosition, 0);
}
}
POOL_END();
Expand Down
Loading