File tree Expand file tree Collapse file tree 1 file changed +32
-2
lines changed
Microsoft.Toolkit.Uwp.UI.Controls.Input/RichSuggestBox Expand file tree Collapse file tree 1 file changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,36 @@ public void ClearUndoRedoSuggestionHistory()
97
97
}
98
98
}
99
99
100
+ /// <summary>
101
+ /// Clear the document and token list. This will also clear the undo/redo history.
102
+ /// </summary>
103
+ public void Clear ( )
104
+ {
105
+ lock ( _tokensLock )
106
+ {
107
+ _tokens . Clear ( ) ;
108
+ _visibleTokens . Clear ( ) ;
109
+ TextDocument . Selection . Expand ( TextRangeUnit . Story ) ;
110
+ TextDocument . Selection . Delete ( TextRangeUnit . Story , 0 ) ;
111
+ TextDocument . ClearUndoRedoHistory ( ) ;
112
+ }
113
+ }
114
+
115
+ /// <summary>
116
+ /// Add tokens to be tracked against the document. Duplicate tokens will not be updated.
117
+ /// </summary>
118
+ /// <param name="tokens">The collection of tokens to be tracked.</param>
119
+ public void AddTokens ( IEnumerable < RichSuggestToken > tokens )
120
+ {
121
+ lock ( _tokensLock )
122
+ {
123
+ foreach ( var token in tokens )
124
+ {
125
+ _tokens . TryAdd ( $ "\" { token . Id } \" ", token ) ;
126
+ }
127
+ }
128
+ }
129
+
100
130
/// <summary>
101
131
/// Try getting the token associated with a text range.
102
132
/// </summary>
@@ -673,7 +703,7 @@ private void ValidateTokenFromRange(ITextRange range)
673
703
674
704
if ( token . ToString ( ) != range . Text )
675
705
{
676
- range . Delete ( TextRangeUnit . Story , - 1 ) ;
706
+ range . Delete ( TextRangeUnit . Story , 0 ) ;
677
707
token . Active = false ;
678
708
return ;
679
709
}
@@ -923,7 +953,7 @@ private void UpdateVisibleTokenList()
923
953
{
924
954
lock ( _tokensLock )
925
955
{
926
- var toBeRemoved = _visibleTokens . Where ( x => ! x . Active ) . ToArray ( ) ;
956
+ var toBeRemoved = _visibleTokens . Where ( x => ! x . Active || ! _tokens . ContainsKey ( $ " \" { x . Id } \" " ) ) . ToArray ( ) ;
927
957
928
958
foreach ( var elem in toBeRemoved )
929
959
{
You can’t perform that action at this time.
0 commit comments