Skip to content

Commit d091e6a

Browse files
committed
protected LockObj -> private _tokensLock
1 parent a2b3880 commit d091e6a

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,6 @@ public DisabledFormattingAccelerators DisabledFormattingAccelerators
346346
set => SetValue(DisabledFormattingAcceleratorsProperty, value);
347347
}
348348

349-
/// <summary>
350-
/// Gets object used for lock
351-
/// </summary>
352-
protected object LockObj { get; }
353-
354349
/// <summary>
355350
/// Gets an object that enables access to the text object model for the text contained in a <see cref="RichEditBox"/>.
356351
/// </summary>

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public partial class RichSuggestBox : ItemsControl
4040
private const string PartHeaderContentPresenter = "HeaderContentPresenter";
4141
private const string PartDescriptionPresenter = "DescriptionPresenter";
4242

43+
private readonly object _tokensLock;
4344
private readonly Dictionary<string, RichSuggestToken> _tokens;
4445
private readonly ObservableCollection<RichSuggestToken> _visibleTokens;
4546

@@ -61,10 +62,10 @@ public partial class RichSuggestBox : ItemsControl
6162
/// </summary>
6263
public RichSuggestBox()
6364
{
65+
_tokensLock = new object();
6466
_tokens = new Dictionary<string, RichSuggestToken>();
6567
_visibleTokens = new ObservableCollection<RichSuggestToken>();
6668
Tokens = new ReadOnlyObservableCollection<RichSuggestToken>(_visibleTokens);
67-
LockObj = new object();
6869

6970
DefaultStyleKey = typeof(RichSuggestBox);
7071

@@ -81,7 +82,7 @@ public RichSuggestBox()
8182
public void ClearUndoRedoSuggestionHistory()
8283
{
8384
TextDocument.ClearUndoRedoHistory();
84-
lock (LockObj)
85+
lock (_tokensLock)
8586
{
8687
if (_tokens.Count == 0)
8788
{
@@ -108,7 +109,7 @@ public bool TryGetTokenFromRange(ITextRange range, out RichSuggestToken token)
108109
range = range.GetClone();
109110
if (range != null && !string.IsNullOrEmpty(range.Link))
110111
{
111-
lock (LockObj)
112+
lock (_tokensLock)
112113
{
113114
return _tokens.TryGetValue(range.Link, out token);
114115
}
@@ -272,7 +273,7 @@ private void RichEditBox_SelectionChanging(RichEditBox sender, RichEditBoxSelect
272273

273274
var range = selection.GetClone();
274275
range.Expand(TextRangeUnit.Link);
275-
lock (LockObj)
276+
lock (_tokensLock)
276277
{
277278
if (!_tokens.ContainsKey(range.Link))
278279
{
@@ -580,7 +581,7 @@ internal async Task CommitSuggestionAsync(object selectedItem)
580581
return;
581582
}
582583

583-
lock (LockObj)
584+
lock (_tokensLock)
584585
{
585586
var displayText = prefix + text;
586587

@@ -634,7 +635,7 @@ private bool TryCommitSuggestionIntoDocument(ITextRange range, string displayTex
634635

635636
private void ValidateTokensInDocument()
636637
{
637-
lock (LockObj)
638+
lock (_tokensLock)
638639
{
639640
foreach (var (_, token) in _tokens)
640641
{
@@ -655,7 +656,7 @@ private void ValidateTokenFromRange(ITextRange range)
655656
// Check for duplicate tokens. This can happen if the user copies and pastes the token multiple times.
656657
if (token.Active && token.RangeStart != range.StartPosition && token.RangeEnd != range.EndPosition)
657658
{
658-
lock (LockObj)
659+
lock (_tokensLock)
659660
{
660661
var guid = Guid.NewGuid();
661662
if (TryCommitSuggestionIntoDocument(range, token.DisplayText, guid, CreateTokenFormat(range), false))
@@ -919,7 +920,7 @@ private ITextCharacterFormat CreateTokenFormat(ITextRange range)
919920

920921
private void UpdateVisibleTokenList()
921922
{
922-
lock (LockObj)
923+
lock (_tokensLock)
923924
{
924925
var toBeRemoved = _visibleTokens.Where(x => !x.Active).ToArray();
925926

0 commit comments

Comments
 (0)