Skip to content

Commit

Permalink
Merge pull request #3281 from smoogipoo/fix-rearrangeablelist-scrollt…
Browse files Browse the repository at this point in the history
…otop

Fix rearrangeable list scrolled to top on single item removal
  • Loading branch information
peppy authored Feb 18, 2020
2 parents 952fe8c + 4fd5e28 commit ae06013
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,23 @@ public void TestRearrangeWhileRemovingItems()
AddStep("release button", () => InputManager.ReleaseButton(MouseButton.Left));
}

[Test]
public void TestNotScrolledToTopOnRemove()
{
addItems(100);

float scrollPosition = 0;
AddStep("scroll to item 50", () =>
{
list.ScrollTo(50);
scrollPosition = list.ScrollPosition;
});

AddStep("remove item 50", () => list.Items.Remove(50));

AddAssert("scroll hasn't changed", () => list.ScrollPosition == scrollPosition);
}

private void addDragSteps(int from, int to, int[] expectedSequence)
{
AddStep($"move to {from}", () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ private void collectionChanged(object sender, NotifyCollectionChangedEventArgs e

// Explicitly reset scroll position here so that ScrollContainer doesn't retain our
// scroll position if we quickly add new items after calling a Clear().
ScrollContainer.ScrollToStart();
if (Items.Count == 0)
ScrollContainer.ScrollToStart();
break;

case NotifyCollectionChangedAction.Reset:
Expand Down

0 comments on commit ae06013

Please sign in to comment.