Skip to content

Commit

Permalink
fix: [3851] fixed iOS losing cursor position when using predictive text
Browse files Browse the repository at this point in the history
Fixes #3851
  • Loading branch information
Steve Hannah committed Feb 22, 2025
1 parent 957aa8b commit 4cf369d
Showing 1 changed file with 11 additions and 1 deletion.
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

0 comments on commit 4cf369d

Please sign in to comment.