Skip to content

Commit 1bc820b

Browse files
SyedAbdulAzeemSF4852kubaflo
authored andcommitted
Updated the fix by setting the cursor position before updating the text and removing the clamping logic based on text length
1 parent 4c709ac commit 1bc820b

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

src/Core/src/Core/Extensions/ITextInputExtensions.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,9 @@ public static bool TextWithinMaxLength(this ITextInput textInput, string? text,
5353

5454
internal static void UpdateCursorPosition(this ITextInput textInput, int cursorPosition)
5555
{
56-
// Validate cursor position bounds
57-
var textLength = textInput.Text?.Length ?? 0;
58-
var validatedCursorPosition = Math.Clamp(cursorPosition, 0, textLength);
59-
60-
if (textInput.CursorPosition != validatedCursorPosition)
56+
if (textInput.CursorPosition != cursorPosition)
6157
{
62-
textInput.CursorPosition = validatedCursorPosition;
58+
textInput.CursorPosition = cursorPosition;
6359
}
6460
}
6561
#endif

src/Core/src/Handlers/Entry/EntryHandler.iOS.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,16 @@ void OnEditingBegan(object? sender, EventArgs e)
190190

191191
void OnEditingChanged(object? sender, EventArgs e)
192192
{
193-
if (sender is MauiTextField platformView)
193+
if (sender is MauiTextField platformView && VirtualView is not null)
194194
{
195-
VirtualView?.UpdateText(platformView.Text);
196-
VirtualView?.UpdateCursorPosition(platformView.GetCursorPosition());
197-
}
198-
}
195+
// Update cursor position before updating text so that when TextChanged event fires,
196+
// the CursorPosition property reflects the current native cursor position
197+
VirtualView.UpdateCursorPosition(platformView.GetCursorPosition());
199198

199+
VirtualView.UpdateText(platformView.Text);
200+
}
201+
}
202+
200203
void OnEditingEnded(object? sender, EventArgs e)
201204
{
202205
if (sender is MauiTextField platformView && VirtualView is IEntry virtualView)

0 commit comments

Comments
 (0)