Skip to content

Commit 7b669e8

Browse files
committed
Fix TTB remove crash
1 parent aa33eaf commit 7b669e8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Microsoft.Toolkit.Uwp.UI.Controls/TokenizingTextBox/TokenizingTextBox.Selection.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,14 @@ internal async Task RemoveAllSelectedTokens()
247247
{
248248
var currentContainerItem = FocusManager.GetFocusedElement() as TokenizingTextBoxItem;
249249

250-
for (int i = SelectedItems.Count - 1; i >= 0; i--)
250+
while (SelectedItems.Count > 0)
251251
{
252-
var container = ContainerFromItem(SelectedItems[i]) as TokenizingTextBoxItem;
252+
var container = ContainerFromItem(SelectedItems[0]) as TokenizingTextBoxItem;
253253

254254
if (IndexFromContainer(container) != Items.Count - 1)
255255
{
256256
// if its a text box, remove any selected text, and if its then empty remove the container, unless its focused
257-
if (SelectedItems[i] is ITokenStringContainer)
257+
if (SelectedItems[0] is ITokenStringContainer)
258258
{
259259
var asb = container._autoSuggestTextBox;
260260

@@ -288,6 +288,15 @@ internal async Task RemoveAllSelectedTokens()
288288
await RemoveTokenAsync(container);
289289
}
290290
}
291+
else
292+
{
293+
if (SelectedItems.Count == 1)
294+
{
295+
// at this point we have one selection and its the default textbox.
296+
// stop the iteration here
297+
break;
298+
}
299+
}
291300
}
292301
}
293302

0 commit comments

Comments
 (0)