-
Notifications
You must be signed in to change notification settings - Fork 779
Fixes #5366 - BREAKING CHANGE - Make View.Text notifications CWP-compliant and non-virtual #5371
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
Open
tig
wants to merge
14
commits into
develop
Choose a base branch
from
tig/tig-issue-5366-view-text-cwp-compliant
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c316b31
BREAKING CHANGE: Fixes #5366. Make View.Text notifications CWP-compliant
tig 9ad0d8a
BREAKING CHANGE: Make View.Text non-virtual; migrate all overrides to…
tig 3173757
Fix CI: ReactiveExample source generator conflict and XML cref warnings
tig fdd4ea2
Address CR feedback: CWP compliance, polymorphic sync, ProgressBar fa…
tig 5246356
Fix TextField and TextView to raise View.TextChanging in their setters
tig 20affe7
Remove TextField's 'new Text' - use CWP overrides instead
tig f2c8fbd
code cleanup
tig 7136a23
Remove public RaiseTextChanging - inline into OnTextChanging override
tig 8119c93
Refactor View.Text setter to use SetTextDirect
tig 1f53a59
cleanup
tig 5346be2
Minimize TextField diff: remove member reordering churn
tig 41a3cc3
Fix CR feedback: move validation to OnTextChanging, protect RaiseText…
tig 5e2f2a6
Add Text↔Value consistency tests for DatePicker, ColorPicker, TextVal…
tig af4b5df
Merge origin/develop and resolve conflicts
Copilot 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
Some comments aren't visible on the classic Files Changed page.
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
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
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,151 @@ | ||
| // Copilot | ||
|
|
||
| using System.ComponentModel; | ||
|
|
||
| namespace ViewBaseTests; | ||
|
|
||
| /// <summary> | ||
| /// Tests for the CWP-compliant <see cref="View.Text"/> notifications: | ||
| /// <see cref="View.TextChanging"/> and <see cref="View.TextChanged"/>. | ||
| /// </summary> | ||
| public class TextCwpTests | ||
| { | ||
| [Fact] | ||
| public void Text_SetSameValue_NoEventsRaised () | ||
| { | ||
| View view = new () { Text = "hello" }; | ||
| bool changingRaised = false; | ||
| bool changedRaised = false; | ||
| view.TextChanging += (_, _) => changingRaised = true; | ||
| view.TextChanged += (_, _) => changedRaised = true; | ||
|
|
||
| view.Text = "hello"; | ||
|
|
||
| Assert.False (changingRaised); | ||
| Assert.False (changedRaised); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Text_SetDifferentValue_BothEventsRaised () | ||
| { | ||
| View view = new () { Text = "old" }; | ||
| bool changingRaised = false; | ||
| bool changedRaised = false; | ||
| view.TextChanging += (_, _) => changingRaised = true; | ||
| view.TextChanged += (_, _) => changedRaised = true; | ||
|
|
||
| view.Text = "new"; | ||
|
|
||
| Assert.True (changingRaised); | ||
| Assert.True (changedRaised); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TextChanging_Cancel_PreventsTextChange () | ||
| { | ||
| View view = new () { Text = "original" }; | ||
| view.TextChanging += (_, e) => e.Cancel = true; | ||
|
|
||
| view.Text = "modified"; | ||
|
|
||
| Assert.Equal ("original", view.Text); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TextChanging_Cancel_SuppressesTextChanged () | ||
| { | ||
| View view = new () { Text = "original" }; | ||
| bool changedRaised = false; | ||
| view.TextChanging += (_, e) => e.Cancel = true; | ||
| view.TextChanged += (_, _) => changedRaised = true; | ||
|
|
||
| view.Text = "modified"; | ||
|
|
||
| Assert.False (changedRaised); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TextChanging_RaisedBeforeMutation () | ||
| { | ||
| View view = new () { Text = "before" }; | ||
| string? textDuringChanging = null; | ||
| view.TextChanging += (sender, _) => textDuringChanging = ((View)sender!).Text; | ||
|
|
||
| view.Text = "after"; | ||
|
|
||
| Assert.Equal ("before", textDuringChanging); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TextChanged_RaisedAfterMutation () | ||
| { | ||
| View view = new () { Text = "before" }; | ||
| string? textDuringChanged = null; | ||
| view.TextChanged += (sender, _) => textDuringChanged = ((View)sender!).Text; | ||
|
|
||
| view.Text = "after"; | ||
|
|
||
| Assert.Equal ("after", textDuringChanged); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void OnTextChanging_Override_CanCancel () | ||
| { | ||
| CancellingView view = new (); | ||
| // Set initial text before enabling cancellation | ||
| view.AllowChange = true; | ||
| view.Text = "initial"; | ||
| view.AllowChange = false; | ||
|
|
||
| view.Text = "blocked"; | ||
|
|
||
| Assert.Equal ("initial", view.Text); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void OnTextChanged_Override_CalledAfterChange () | ||
| { | ||
| TrackingView view = new () { Text = "start" }; | ||
|
|
||
| view.Text = "end"; | ||
|
|
||
| Assert.True (view.OnTextChangedCalled); | ||
| Assert.Equal ("end", view.TextAtOnTextChanged); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TextChanging_EventOrder_ChangingBeforeChanged () | ||
| { | ||
| View view = new () { Text = "a" }; | ||
| List<string> order = []; | ||
| view.TextChanging += (_, _) => order.Add ("changing"); | ||
| view.TextChanged += (_, _) => order.Add ("changed"); | ||
|
|
||
| view.Text = "b"; | ||
|
|
||
| Assert.Equal (["changing", "changed"], order); | ||
| } | ||
|
|
||
| /// <summary>A test subclass that cancels text changes via <see cref="View.OnTextChanging"/>.</summary> | ||
| private class CancellingView : View | ||
| { | ||
| public bool AllowChange { get; set; } | ||
|
|
||
| protected override bool OnTextChanging () => !AllowChange; | ||
| } | ||
|
|
||
| /// <summary>A test subclass that tracks calls to <see cref="View.OnTextChanged"/>.</summary> | ||
| private class TrackingView : View | ||
| { | ||
| public bool OnTextChangedCalled { get; private set; } | ||
| public string? TextAtOnTextChanged { get; private set; } | ||
|
|
||
| protected override void OnTextChanged () | ||
| { | ||
| OnTextChangedCalled = true; | ||
| TextAtOnTextChanged = Text; | ||
|
|
||
| base.OnTextChanged (); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.