@@ -50,12 +50,10 @@ public partial class RichSuggestBox : ItemsControl
50
50
private Border _suggestionsContainer ;
51
51
52
52
private int _suggestionChoice ;
53
- private string _currentQuery ;
54
- private string _currentPrefix ;
55
53
private bool _ignoreChange ;
56
54
private bool _popupOpenDown ;
57
55
private bool _textCompositionActive ;
58
- private ITextRange _currentRange ;
56
+ private RichSuggestQuery _currentQuery ;
59
57
private CancellationTokenSource _suggestionRequestedCancellationSource ;
60
58
61
59
/// <summary>
@@ -70,7 +68,6 @@ public RichSuggestBox()
70
68
71
69
DefaultStyleKey = typeof ( RichSuggestBox ) ;
72
70
73
- RegisterPropertyChangedCallback ( ItemsSourceProperty , ItemsSource_PropertyChanged ) ;
74
71
RegisterPropertyChangedCallback ( CornerRadiusProperty , OnCornerRadiusChanged ) ;
75
72
RegisterPropertyChangedCallback ( PopupCornerRadiusProperty , OnCornerRadiusChanged ) ;
76
73
LostFocus += OnLostFocus ;
@@ -405,12 +402,6 @@ private void RichEditBox_SizeChanged(object sender, SizeChangedEventArgs e)
405
402
this . UpdatePopupOffset ( ) ;
406
403
}
407
404
408
- private void ItemsSource_PropertyChanged ( DependencyObject sender , DependencyProperty dp )
409
- {
410
- _suggestionChoice = 0 ;
411
- ShowSuggestionsPopup ( _suggestionsList ? . Items ? . Count > 0 ) ;
412
- }
413
-
414
405
private async void RichEditBox_Paste ( object sender , TextControlPasteEventArgs e )
415
406
{
416
407
Paste ? . Invoke ( this , e ) ;
@@ -501,12 +492,13 @@ private async Task RequestSuggestionsAsync(ITextRange range = null)
501
492
{
502
493
string prefix ;
503
494
string query ;
495
+ var currentQuery = _currentQuery ;
504
496
var queryFound = range == null
505
497
? TryExtractQueryFromSelection ( out prefix , out query , out range )
506
498
: TryExtractQueryFromRange ( range , out prefix , out query ) ;
507
499
508
- if ( queryFound && prefix == _currentPrefix && query == _currentQuery &&
509
- range . EndPosition == _currentRange ? . EndPosition && _suggestionPopup . IsOpen )
500
+ if ( queryFound && prefix == currentQuery ? . Prefix && query == currentQuery ? . QueryText &&
501
+ range . EndPosition == currentQuery ? . Range . EndPosition && _suggestionPopup . IsOpen )
510
502
{
511
503
return ;
512
504
}
@@ -516,9 +508,7 @@ private async Task RequestSuggestionsAsync(ITextRange range = null)
516
508
517
509
if ( queryFound )
518
510
{
519
- _currentPrefix = prefix ;
520
- _currentQuery = query ;
521
- _currentRange = range ;
511
+ _currentQuery = new RichSuggestQuery { Prefix = prefix , QueryText = query , Range = range } ;
522
512
523
513
if ( SuggestionsRequested != null )
524
514
{
@@ -532,7 +522,13 @@ private async Task RequestSuggestionsAsync(ITextRange range = null)
532
522
}
533
523
catch ( OperationCanceledException )
534
524
{
535
- // pass
525
+ return ;
526
+ }
527
+
528
+ if ( ! eventArgs . Cancel )
529
+ {
530
+ _suggestionChoice = 0 ;
531
+ ShowSuggestionsPopup ( _suggestionsList ? . Items ? . Count > 0 ) ;
536
532
}
537
533
}
538
534
}
@@ -544,10 +540,11 @@ private async Task RequestSuggestionsAsync(ITextRange range = null)
544
540
545
541
internal async Task CommitSuggestionAsync ( object selectedItem )
546
542
{
547
- var range = _currentRange ? . GetClone ( ) ;
543
+ var currentQuery = _currentQuery ;
544
+ var range = currentQuery ? . Range . GetClone ( ) ;
548
545
var id = Guid . NewGuid ( ) ;
549
- var prefix = _currentPrefix ;
550
- var query = _currentQuery ;
546
+ var prefix = currentQuery ? . Prefix ;
547
+ var query = currentQuery ? . QueryText ;
551
548
552
549
// range has length of 0 at the end of the commit.
553
550
// Checking length == 0 to avoid committing twice.
0 commit comments