-
Notifications
You must be signed in to change notification settings - Fork 2k
[Windows] Fix select-all Entry select logic #23329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7065e1b
Ensure `CursorPosition` and `SelectionLength` always fire change even…
2eb73bd
Add visual test
9f0a0b4
Switch to use `Handler?.UpdateValue` in `CursorPosition` and `Selecti…
f148728
Change to more basic func
f524584
Last change ;)
bbdbe25
Ensure `CursorPosition` and `SelectionLength` always fire change even…
19f42ec
Add visual test
b93b0c3
Switch to use `Handler?.UpdateValue` in `CursorPosition` and `Selecti…
e5adfdb
Change to more basic func
ab808ea
Last change ;)
eba2b8a
Merge branch 'foda/EntrySelect' of https://github.com/dotnet/maui int…
8d78872
Update fix to use OnBindablePropertySet
a11d30f
Merge branch 'main' into foda/EntrySelect
Foda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/Controls/tests/TestCases.HostApp/Issues/EntrySelectionTest.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| x:Class="Maui.Controls.Sample.Issues.EntrySelectionTest" | ||
| Title="EntrySelectionTest" | ||
| Background="White"> | ||
| <VerticalStackLayout> | ||
| <Entry | ||
| x:Name="TextBox" | ||
| AutomationId="TextBox" | ||
| WidthRequest="300" | ||
| Focused="OnTextBoxFocused"/> | ||
| <Button | ||
| x:Name="OtherElement" | ||
| AutomationId="OtherElement" | ||
| Text="Other" | ||
| WidthRequest="128"/> | ||
| </VerticalStackLayout> | ||
| </ContentPage> |
20 changes: 20 additions & 0 deletions
20
src/Controls/tests/TestCases.HostApp/Issues/EntrySelectionTest.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [XamlCompilation(XamlCompilationOptions.Compile)] | ||
| [Issue(IssueTracker.ManualTest, "EntrySelectionTest", "Entry select all text issue", PlatformAffected.UWP)] | ||
| public partial class EntrySelectionTest : ContentPage | ||
| { | ||
| public EntrySelectionTest() | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
|
|
||
| void OnTextBoxFocused(object sender, FocusEventArgs e) | ||
| { | ||
| if (TextBox.Text != null) | ||
| { | ||
| TextBox.CursorPosition = 0; | ||
| TextBox.SelectionLength = TextBox.Text.Length; | ||
| } | ||
| } | ||
| } | ||
31 changes: 31 additions & 0 deletions
31
src/Controls/tests/TestCases.WinUI.Tests/EntrySelectionTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests; | ||
|
|
||
| public class EntrySelectionTest : _IssuesUITest | ||
| { | ||
| public EntrySelectionTest(TestDevice device) | ||
| : base(device) | ||
| { } | ||
|
|
||
| public override string Issue => "Entry select all text issue"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Entry)] | ||
| public void VerifySelectWorks() | ||
| { | ||
| App.WaitForElement("TextBox"); | ||
| App.Click("TextBox"); | ||
| App.EnterText("TextBox", "Hello World"); | ||
|
|
||
| App.Click("OtherElement"); | ||
| App.Click("TextBox"); | ||
|
|
||
| App.Click("OtherElement"); | ||
| App.Click("TextBox"); | ||
|
|
||
| VerifyScreenshot(); | ||
| } | ||
| } |
Binary file added
BIN
+4.86 KB
src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifySelectWorks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #nullable enable | ||
| using System; | ||
| using System.Diagnostics; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] Windows Platform Specifics — |
||
| using Microsoft.Maui.Graphics; | ||
| using Microsoft.UI.Xaml.Controls; | ||
| using Microsoft.UI.Xaml.Input; | ||
|
|
@@ -204,7 +205,10 @@ public static void UpdateVerticalTextAlignment(this TextBox textBox, ITextAlignm | |
| public static void UpdateCursorPosition(this TextBox textBox, ITextInput entry) | ||
| { | ||
| // It seems that the TextBox does not limit the CursorPosition to the Text.Length natively | ||
| entry.CursorPosition = Math.Min(entry.CursorPosition, textBox.Text.Length); | ||
| var clampedPos = Math.Min(entry.CursorPosition, textBox.Text.Length); | ||
|
|
||
| if (entry.CursorPosition != clampedPos) | ||
| entry.CursorPosition = clampedPos; | ||
|
|
||
| if (textBox.SelectionStart != entry.CursorPosition) | ||
| textBox.SelectionStart = entry.CursorPosition; | ||
|
|
@@ -213,7 +217,10 @@ public static void UpdateCursorPosition(this TextBox textBox, ITextInput entry) | |
| public static void UpdateSelectionLength(this TextBox textBox, ITextInput entry) | ||
| { | ||
| // It seems that the TextBox does not limit the SelectionLength to the Text.Length natively | ||
| entry.SelectionLength = Math.Min(entry.SelectionLength, textBox.Text.Length - textBox.SelectionStart); | ||
| var clampedLen = Math.Min(entry.SelectionLength, textBox.Text.Length - textBox.SelectionStart); | ||
|
|
||
| if (entry.SelectionLength != clampedLen) | ||
| entry.SelectionLength = clampedLen; | ||
|
|
||
| if (textBox.SelectionLength != entry.SelectionLength) | ||
| textBox.SelectionLength = entry.SelectionLength; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[moderate] Regression Prevention —
IssueTracker.ManualTestwith a string key is the pattern for issues without a GitHub number, but this PR has an automated WinUI test (EntrySelectionTest.cs) so it should useIssueTracker.Github, <issue_number>. AdditionallyPlatformAffected.UWPis the legacy Xamarin.Forms label; the correct value for this repo isPlatformAffected.Windows(orPlatformAffected.Allif the fix is intended cross-platform). UsingManualTestmeans the test runner may not correlate this page with the automated test class correctly.