Skip to content

SelectionLength property update when entry is focused - fix - #26213

Merged
kubaflo merged 5 commits into
dotnet:inflight/currentfrom
kubaflo:fix-26158
Mar 20, 2026
Merged

kubaflo merged 5 commits into
dotnet:inflight/currentfrom
kubaflo:fix-26158

Conversation

@kubaflo

@kubaflo kubaflo commented Nov 29, 2024

Copy link
Copy Markdown
Contributor

Issues Fixed

Fixes #26158

Before After
Screen.Recording.2024-11-29.at.02.38.46.mov
Screen.Recording.2024-11-29.at.02.36.32.mov

@kubaflo
kubaflo requested a review from a team as a code owner November 29, 2024 01:59
@kubaflo
kubaflo requested review from Eilon and tj-devel709 November 29, 2024 01:59
@PureWeen PureWeen added this to the .NET 9 SR4 milestone Jan 5, 2025

@jsuarezruiz jsuarezruiz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are several device tests related with the cursor position, selection etc failing:
image

For example:
image

@kubaflo

kubaflo commented Jan 17, 2025

Copy link
Copy Markdown
Contributor Author

@jsuarezruiz tests should pass now

@kubaflo
kubaflo requested a review from jsuarezruiz January 17, 2025 16:55
@PureWeen PureWeen modified the milestones: .NET 9 SR4, .NET 9 SR5 Jan 29, 2025
@sheiksyedm

Copy link
Copy Markdown
Contributor

@kubaflo The fix only resolves the issue when clicking the right corner of the Entry without touching the text area. If we click to focus over the text area, the issue still persists. When dynamically updating the Entry's SelectionLength on the focus event, it works as expected without the fix. Please check the video below. I'm not sure if this fix is really needed or if this issue represents a proper use case.

Screen.Recording.2025-02-12.at.7.39.46.PM.mov

@jsuarezruiz

Copy link
Copy Markdown
Contributor

/rebase

@mattleibow mattleibow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code idea looks good, but the GC and/or manual disposal may break it.

  • Maybe check IsAlive first
  • Enable tests for Windows/macOS as this is a core feature for all platforms

@@ -0,0 +1,23 @@
#if ANDROID || IOS

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a reason this is not for windows and mac as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure it will work, but let's try

@github-project-automation github-project-automation Bot moved this from Ready To Review to Changes Requested in MAUI SDK Ongoing Mar 3, 2025
@mattleibow

Copy link
Copy Markdown
Member

@kubaflo any thoughts on the comment by @sheiksyedm ?

@kubaflo

kubaflo commented Mar 3, 2025

Copy link
Copy Markdown
Contributor Author

@kubaflo The fix only resolves the issue when clicking the right corner of the Entry without touching the text area. If we click to focus over the text area, the issue still persists. When dynamically updating the Entry's SelectionLength on the focus event, it works as expected without the fix. Please check the video below. I'm not sure if this fix is really needed or if this issue represents a proper use case.

Screen.Recording.2025-02-12.at.7.39.46.PM.mov

This is what this PR aims to resolve

@kubaflo

kubaflo commented Mar 3, 2025

Copy link
Copy Markdown
Contributor Author

@mattleibow I didn't find any iOS extension so I've simply added
if (textField is not null && textField.Handle != IntPtr.Zero)

@PureWeen PureWeen moved this from Changes Requested to Ready To Review in MAUI SDK Ongoing Mar 4, 2025
@rmarinho

rmarinho commented Mar 6, 2025

Copy link
Copy Markdown
Member

/rebase

@rmarinho

rmarinho commented Mar 6, 2025

Copy link
Copy Markdown
Member

/azp run

Copilot AI review requested due to automatic review settings March 19, 2026 17:03
@github-actions

github-actions Bot commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 26213

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 26213"

@kubaflo

kubaflo commented Mar 19, 2026

Copy link
Copy Markdown
Contributor Author

/azp run maui-pr-uitests

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes .NET MAUI Entry SelectionLength updates not being applied when the control is focused (Android/iOS), addressing #26158 by deferring selection updates until the native control is ready to accept them.

Changes:

  • iOS: defer UITextField.SelectedTextRange updates via main-queue dispatch when IEntry.IsFocused is true.
  • Android: defer EditText.SetSelection(start, end) via Post(...) when the view is focused.
  • Add a HostApp repro page + Appium UI test with Android/iOS snapshot baselines.

Reviewed changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Core/src/Platform/iOS/TextFieldExtensions.cs Defers selection updates on iOS when focused to ensure selection takes effect.
src/Core/src/Platform/Android/EditTextExtensions.cs Defers selection updates on Android when focused via Post(...).
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26158.cs Adds Appium UI test validating selection behavior via screenshot.
src/Controls/tests/TestCases.HostApp/Issues/Issue26158.cs Adds HostApp reproduction page for the issue.
src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/SelectionLengthShouldUpdateWhenEntryIsFocused.png Adds iOS snapshot baseline for the new test.
src/Controls/tests/TestCases.Android.Tests/snapshots/android/SelectionLengthShouldUpdateWhenEntryIsFocused.png Adds Android snapshot baseline for the new test.

{
if (editText.IsAlive())
{
editText.SetSelection(start, end);
Comment on lines +17 to +23
App.WaitForElement("entry");
App.Click("entry");
#if ANDROID
App.DismissKeyboard();
#endif
VerifyScreenshot();
}
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

kubaflo and others added 5 commits March 20, 2026 00:24
The PR implementation covers both Android and iOS, so the issue
attribute should reflect both affected platforms.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@MauiBot MauiBot added s/agent-review-incomplete and removed s/agent-changes-requested AI agent recommends changes - found a better alternative or issues labels Mar 20, 2026
@dotnet dotnet deleted a comment from MauiBot Mar 20, 2026
@kubaflo

kubaflo commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

/azp run maui-pr-uitests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@kubaflo
kubaflo changed the base branch from main to inflight/current March 20, 2026 23:30
@kubaflo kubaflo added the s/agent-fix-implemented PR author implemented the agent suggested fix label Mar 20, 2026
@kubaflo
kubaflo merged commit ef684e4 into dotnet:inflight/current Mar 20, 2026
143 of 154 checks passed
PureWeen pushed a commit that referenced this pull request Mar 24, 2026
### Issues Fixed

Fixes #26158

|Before|After|
|--|--|
|<video
src="https://github.com/user-attachments/assets/a0b6cebe-7fd4-4705-b32e-81cf3fe34ec7"
width="300px"/>|<video
src="https://github.com/user-attachments/assets/d77f61e9-f198-4fab-8c18-fdab000f94ce"
width="300px"/>|

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
KarthikRajaKalaimani pushed a commit to KarthikRajaKalaimani/maui that referenced this pull request Mar 30, 2026
…6213)

### Issues Fixed

Fixes dotnet#26158

|Before|After|
|--|--|
|<video
src="https://github.com/user-attachments/assets/a0b6cebe-7fd4-4705-b32e-81cf3fe34ec7"
width="300px"/>|<video
src="https://github.com/user-attachments/assets/d77f61e9-f198-4fab-8c18-fdab000f94ce"
width="300px"/>|

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-entry Entry community ✨ Community Contribution partner/syncfusion/review platform/android platform/ios s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-implemented PR author implemented the agent suggested fix s/agent-fix-win AI found a better alternative fix than the PR s/agent-gate-failed AI could not verify tests catch the bug s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SelectionLength Property Not Applied to Entry at Runtime

9 participants