Skip to content

Commit c363f62

Browse files
committed
improve clarity for SuggestionChosenEventArgs
1 parent 58a3cde commit c363f62

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/RichSuggestBox/RichSuggestBoxPage.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ private void SuggestingBox_OnSuggestionChosen(RichSuggestBox sender, SuggestionC
167167
args.Format.ForegroundColor = Colors.OrangeRed;
168168
args.Format.Bold = FormatEffect.On;
169169
args.Format.Italic = FormatEffect.On;
170-
args.Text = ((SampleDataType)args.SelectedItem).Text;
170+
args.DisplayText = ((SampleDataType)args.SelectedItem).Text;
171171
}
172172
else
173173
{
174-
args.Text = ((SampleEmailDataType)args.SelectedItem).DisplayName;
174+
args.DisplayText = ((SampleEmailDataType)args.SelectedItem).DisplayName;
175175
}
176176
}
177177

Microsoft.Toolkit.Uwp.UI.Controls.Input/RichSuggestBox/RichSuggestBox.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,22 +555,23 @@ internal async Task CommitSuggestionAsync(object selectedItem)
555555
}
556556

557557
var textBefore = range.Text;
558+
var format = CreateTokenFormat(range);
558559
var eventArgs = new SuggestionChosenEventArgs
559560
{
560561
Id = id,
561562
Prefix = prefix,
562563
QueryText = query,
563564
SelectedItem = selectedItem,
564-
Text = query,
565-
Format = CreateTokenFormat(range)
565+
DisplayText = query,
566+
Format = format
566567
};
567568

568569
if (SuggestionChosen != null)
569570
{
570571
await SuggestionChosen.InvokeAsync(this, eventArgs);
571572
}
572573

573-
var text = eventArgs.Text;
574+
var text = eventArgs.DisplayText;
574575

575576
// Since this operation is async, the document may have changed at this point.
576577
// Double check if the range still has the expected query.
@@ -586,7 +587,7 @@ internal async Task CommitSuggestionAsync(object selectedItem)
586587
var displayText = prefix + text;
587588

588589
_ignoreChange = true;
589-
var committed = TryCommitSuggestionIntoDocument(range, displayText, id, eventArgs.Format);
590+
var committed = TryCommitSuggestionIntoDocument(range, displayText, id, eventArgs.Format ?? format);
590591
TextDocument.EndUndoGroup();
591592
TextDocument.BeginUndoGroup();
592593
_ignoreChange = false;

Microsoft.Toolkit.Uwp.UI.Controls.Input/RichSuggestBox/SuggestionChosenEventArgs.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class SuggestionChosenEventArgs : DeferredEventArgs
2626
/// <summary>
2727
/// Gets or sets the display text.
2828
/// </summary>
29-
public string Text { get; set; }
29+
public string DisplayText { get; set; }
3030

3131
/// <summary>
3232
/// Gets the suggestion item associated with this token.
@@ -39,8 +39,8 @@ public class SuggestionChosenEventArgs : DeferredEventArgs
3939
public Guid Id { get; internal set; }
4040

4141
/// <summary>
42-
/// Gets the formatting construct to override this token formatting.
42+
/// Gets or sets the <see cref="ITextCharacterFormat"/> object used to format the display text for this token.
4343
/// </summary>
44-
public ITextCharacterFormat Format { get; internal set; }
44+
public ITextCharacterFormat Format { get; set; }
4545
}
4646
}

UITests/UITests.Tests.Shared/Controls/RichSuggestBoxTestPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private void RichSuggestBox_OnSuggestionsRequested(RichSuggestBox sender, Sugges
2727

2828
private void RichSuggestBox_OnSuggestionsChosen(RichSuggestBox sender, SuggestionChosenEventArgs args)
2929
{
30-
args.Text = args.QueryText + (string)args.SelectedItem;
30+
args.DisplayText = args.QueryText + (string)args.SelectedItem;
3131
}
3232
}
3333
}

UnitTests/UnitTests.UWP/UI/Controls/Test_RichSuggestBox.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ await App.DispatcherQueue.EnqueueAsync(async () =>
8282

8383
rsb.SuggestionChosen += (rsb, e) =>
8484
{
85-
e.Text = expectedText.Substring(1);
85+
e.DisplayText = expectedText.Substring(1);
8686
var format = e.Format;
8787
format.BackgroundColor = Windows.UI.Colors.Beige;
8888
format.ForegroundColor = Windows.UI.Colors.Azure;
@@ -244,7 +244,7 @@ void SuggestionChosenHandler(RichSuggestBox sender, SuggestionChosenEventArgs ar
244244
suggestionChosenCalled = true;
245245
Assert.AreEqual(tokenText[0].ToString(), args.Prefix, $"Unexpected prefix in {nameof(RichSuggestBox.SuggestionChosen)}.");
246246
Assert.AreEqual(tokenText.Substring(1), args.QueryText, $"Unexpected query in {nameof(RichSuggestBox.SuggestionChosen)}.");
247-
Assert.AreEqual(args.QueryText, args.Text, $"Unexpected display text in {nameof(RichSuggestBox.SuggestionChosen)}.");
247+
Assert.AreEqual(args.QueryText, args.DisplayText, $"Unexpected display text in {nameof(RichSuggestBox.SuggestionChosen)}.");
248248
Assert.AreSame(tokenText, args.SelectedItem, $"Selected item has unknown object {args.SelectedItem} in {nameof(RichSuggestBox.SuggestionChosen)}.");
249249
}
250250

0 commit comments

Comments
 (0)