Skip to content

Commit

Permalink
[iOS] Double dash in input field fix (#20439)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaflo committed Feb 14, 2024
1 parent d749dc7 commit 15ffcd8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Controls/src/Core/Platform/iOS/Extensions/TextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ static void UpdateText(this IUITextInput textInput, InputView inputView, bool is
// position if needed when the text was modified by a Converter.
var textRange = textInput.GetTextRange(textInput.BeginningOfDocument, textInput.EndOfDocument);
var oldText = textInput.TextInRange(textRange) ?? string.Empty;

// We need this variable because in some cases because of the iOS's
// auto correction eg. eg '--' => '—' the actual text in the input might have
// a different length that the one that has been set in the control.
var newTextLength = textInput.TextInRange(textRange)?.Length ?? 0;

var newText = TextTransformUtilites.GetTransformedText(
inputView?.Text,
textInput.GetSecureTextEntry() ? TextTransform.Default : inputView.TextTransform
Expand All @@ -50,8 +56,8 @@ static void UpdateText(this IUITextInput textInput, InputView inputView, bool is
{
// Re-calculate the cursor offset position if the text was modified by a Converter.
// but if the text is being set by code, let's just move the cursor to the end.
var cursorOffset = newText.Length - oldText.Length;
var cursorPosition = isEditing ? textInput.GetCursorPosition(cursorOffset) : newText.Length;
var cursorOffset = newTextLength - oldText.Length;
var cursorPosition = isEditing ? textInput.GetCursorPosition(cursorOffset) : newTextLength;

textInput.ReplaceText(textRange, newText);

Expand Down

0 comments on commit 15ffcd8

Please sign in to comment.