Skip to content

Commit

Permalink
Fix SelectionModel SelectRange crash (#2001)
Browse files Browse the repository at this point in the history
* Add bounds correction for select range paths

* Add test case for select range crash
  • Loading branch information
marcelwgn authored Feb 26, 2020
1 parent 2570cb0 commit 8419c67
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
54 changes: 38 additions & 16 deletions dev/Repeater/APITests/SelectionModelTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using MUXControlsTestApp.Utilities;
Expand Down Expand Up @@ -940,21 +940,43 @@ public void SelectRangeRegressionTest()
selectionModel.SelectRange(IndexPath.CreateFrom(0), IndexPath.CreateFrom(1, 1));

ValidateSelection(selectionModel,
new List<IndexPath>()
{
Path(0, 0),
Path(0, 1),
Path(0, 2),
Path(0),
Path(1, 0),
Path(1, 1)
},
new List<IndexPath>()
{
Path(),
Path(1)
},
1 /* selectedInnerNodes */);
new List<IndexPath>()
{
Path(0, 0),
Path(0, 1),
Path(0, 2),
Path(0),
Path(1, 0),
Path(1, 1)
},
new List<IndexPath>()
{
Path(),
Path(1)
},
1 /* selectedInnerNodes */);

selectionModel = new SelectionModel() { Source = CreateNestedData(2, 2, 1) };

selectionModel.SelectRange(
Path(1), Path(2));

ValidateSelection(
selectionModel,
new List<IndexPath> {
Path(1,0,0),
Path(1), Path(2),
Path(1,0),Path(1,1),
Path(2,0),Path(2,1),
Path(1,0,1),
Path(1,1,0),Path(1,1,1),
Path(2,0,0),Path(2,0,1),
Path(2,1,0),Path(2,1,1),

},
new List<IndexPath> { IndexPath.CreateFromIndices(new List<int> { }) },
12);

});
}

Expand Down
4 changes: 2 additions & 2 deletions dev/Repeater/SelectionTreeHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ void SelectionTreeHelper::TraverseRangeRealizeChildren(
bool isStartPath = IsSubSet(start, currentPath);
bool isEndPath = IsSubSet(end, currentPath);

int startIndex = depth < start.GetSize() && isStartPath ? start.GetAt(depth) : 0;
int endIndex = depth < end.GetSize() && isEndPath ? end.GetAt(depth) : node->DataCount() - 1;
int startIndex = depth < start.GetSize() && isStartPath ? std::max(0, start.GetAt(depth)) : 0;
int endIndex = depth < end.GetSize() && isEndPath ? std::min(node->DataCount() - 1, end.GetAt(depth)) : node->DataCount() - 1;

for (int i = endIndex; i >= startIndex; i--)
{
Expand Down

0 comments on commit 8419c67

Please sign in to comment.