From 15ffcd85c02aa9c32230828a5b650e2d51f1d3db Mon Sep 17 00:00:00 2001 From: Jakub Florkowski Date: Wed, 14 Feb 2024 15:19:29 +0100 Subject: [PATCH 1/3] [iOS] Double dash in input field fix (#20439) --- .../src/Core/Platform/iOS/Extensions/TextExtensions.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Controls/src/Core/Platform/iOS/Extensions/TextExtensions.cs b/src/Controls/src/Core/Platform/iOS/Extensions/TextExtensions.cs index 6b34f6febe60..73f44ac7f853 100644 --- a/src/Controls/src/Core/Platform/iOS/Extensions/TextExtensions.cs +++ b/src/Controls/src/Core/Platform/iOS/Extensions/TextExtensions.cs @@ -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 @@ -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); From d6fd5d8af24d01592814acc8e7fb9e0b4f9f1f9c Mon Sep 17 00:00:00 2001 From: Jakub Florkowski Date: Wed, 14 Feb 2024 15:21:29 +0100 Subject: [PATCH 2/3] Added a UiTest (#20439) --- .../Issues/Issue20439.xaml | 25 +++++++++++++++++ .../Issues/Issue20439.xaml.cs | 20 +++++++++++++ .../tests/UITests/Tests/Issues/Issue20439.cs | 28 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 src/Controls/samples/Controls.Sample.UITests/Issues/Issue20439.xaml create mode 100644 src/Controls/samples/Controls.Sample.UITests/Issues/Issue20439.xaml.cs create mode 100644 src/Controls/tests/UITests/Tests/Issues/Issue20439.cs diff --git a/src/Controls/samples/Controls.Sample.UITests/Issues/Issue20439.xaml b/src/Controls/samples/Controls.Sample.UITests/Issues/Issue20439.xaml new file mode 100644 index 000000000000..5213dd5a635a --- /dev/null +++ b/src/Controls/samples/Controls.Sample.UITests/Issues/Issue20439.xaml @@ -0,0 +1,25 @@ + + + + + + +