From feed7c3479e05fef1c34d7de2587747c2e287174 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 21 Mar 2016 12:47:21 -0700 Subject: [PATCH] Update moves when there is another move to exactly the previous move target --- src/collection_notifications.cpp | 2 +- tests/collection_change_indices.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/collection_notifications.cpp b/src/collection_notifications.cpp index 5e95e6be..cec46d73 100644 --- a/src/collection_notifications.cpp +++ b/src/collection_notifications.cpp @@ -226,7 +226,7 @@ void CollectionChangeBuilder::move(size_t from, size_t to) // to the other if (move.to >= to && move.to < from) ++move.to; - else if (move.to < to && move.to > from) + else if (move.to <= to && move.to > from) --move.to; continue; } diff --git a/tests/collection_change_indices.cpp b/tests/collection_change_indices.cpp index fcf15e75..dacaefad 100644 --- a/tests/collection_change_indices.cpp +++ b/tests/collection_change_indices.cpp @@ -284,6 +284,17 @@ TEST_CASE("[collection_change] move()") { c.move(6, 12); REQUIRE_INDICES(c.modifications, 9); } + + SECTION("bumps previous moves to the same location") { + c.move(5, 10); + c.move(7, 10); + REQUIRE_MOVES(c, {5, 9}, {8, 10}); + + c = {}; + c.move(5, 10); + c.move(15, 10); + REQUIRE_MOVES(c, {5, 11}, {15, 10}); + } } TEST_CASE("[collection_change] calculate() unsorted") {