Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions src/Core/src/Platform/iOS/TextFieldExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ public static void UpdateIsSpellCheckEnabled(this UITextField textField, IEntry

public static void UpdateMaxLength(this UITextField textField, IEntry entry)
{
var newText = textField.AttributedText.TrimToMaxLength(entry.MaxLength);
if (newText != null && textField.AttributedText != newText)
var attributedText = textField.AttributedText;
var newText = attributedText.TrimToMaxLength(entry.MaxLength);
if (newText is not null && !ReferenceEquals(attributedText, newText))
{
textField.AttributedText = newText;
}
}

public static void UpdatePlaceholder(this UITextField textField, IEntry entry, Color? defaultPlaceholderColor = null)
Expand Down
24 changes: 24 additions & 0 deletions src/Core/tests/DeviceTests/Handlers/Entry/EntryHandlerTests.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,30 @@ public async Task ScrollNextEditor()
await ScrollHelper(async () => await ScrollToNext(entry, editor), entry, editor);
}

[Fact]
public async Task CursorPositionPreservedDuringInsertTextWithTextTransformUppercase()
{
var entry = new EntryStub();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[moderate] Regression Prevention — The test name CursorPositionPreservedDuringInsertTextWithTextTransformUppercase implies a TextTransform=Uppercase scenario, but EntryStub has no TextTransform property and does not implement ITextElement; there is no way to set it. The test exercises the UpdateMaxLength double-access fix via Core EntryHandler + direct InsertText, which is a valid reproduction of the underlying mechanism, but it does not cover the Controls.Entry.MapText path that applies TextTransform and then calls UpdateMaxLength — the exact flow described in issue #36018. Consider using Controls.Entry with TextTransform = TextTransform.Uppercase (via a Controls-layer handler) to match the reported scenario, or rename the test to CursorPositionPreservedDuringInsertText to accurately describe what is actually being tested.


await AttachAndRun(entry, (handler) =>
{
var textField = GetNativeEntry(handler);

textField.BecomeFirstResponder();

foreach (var c in "hello")
{
textField.InsertText(c.ToString());
}

UpdateCursorStartPosition(handler, 2);
Assert.Equal(2, GetCursorStartPosition(handler));

textField.InsertText("x");
Assert.Equal(3, GetCursorStartPosition(handler));
});
}

async Task ScrollHelper(Func<Task> func, params StubBase[] views)
{
EnsureHandlerCreated(builder =>
Expand Down
Loading