Skip to content
Closed
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
29 changes: 29 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue32483.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 32483, "CursorPosition not calculated correctly on behaviors events for iOS devices", PlatformAffected.iOS)]

public class Issue32483 : ContentPage
{
public Issue32483()
{
var stackLayout = new StackLayout();
var label = new Label
{
Text = "CursorPosition :",
};
label.AutomationId = "CursorLabel";
label.HeightRequest = 100;
var entry = new Entry();
entry.Keyboard = Keyboard.Numeric;
entry.TextChanged += (s, e) =>
{
label.Text = "CursorPosition : " + entry.CursorPosition;
};
entry.AutomationId = "TestEntry";
entry.HeightRequest = 100;
stackLayout.Children.Add(label);
stackLayout.Children.Add(entry);
Content = stackLayout;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue32483 : _IssuesUITest
{
public Issue32483(TestDevice device) : base(device)
{
}

public override string Issue => "CursorPosition not calculated correctly on behaviors events for iOS devices";

[Test]
[Category(UITestCategories.Entry)]
public void Issue32483Test()
{
// Tap the button to push the FlyoutPage modally
App.WaitForElement("TestEntry");
App.Tap("TestEntry");
App.EnterText("TestEntry","12345");
App.WaitForElement("CursorPosition : 5");
}
}
9 changes: 9 additions & 0 deletions src/Core/src/Handlers/Entry/EntryHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ void OnEditingChanged(object? sender, EventArgs e)
{
if (sender is MauiTextField platformView)
{
// Update cursor position BEFORE updating text so that when TextChanged event fires,
// the CursorPosition property reflects the current native cursor position
var cursorPosition = platformView.GetCursorPosition();

if (VirtualView?.CursorPosition != cursorPosition)
{
VirtualView?.CursorPosition = cursorPosition;
}

VirtualView?.UpdateText(platformView.Text);
}
}
Expand Down