diff --git a/src/collection_notifications.cpp b/src/collection_notifications.cpp index 110d947f..3fd03df7 100644 --- a/src/collection_notifications.cpp +++ b/src/collection_notifications.cpp @@ -263,7 +263,7 @@ void CollectionChangeBuilder::move(size_t from, size_t to) void CollectionChangeBuilder::move_over(size_t row_ndx, size_t last_row) { REALM_ASSERT(row_ndx <= last_row); - if (row_ndx == last_row) { + if (row_ndx == last_row || row_ndx + 1 == last_row) { erase(row_ndx); return; } diff --git a/tests/collection_change_indices.cpp b/tests/collection_change_indices.cpp index c4fbafb7..8526fd07 100644 --- a/tests/collection_change_indices.cpp +++ b/tests/collection_change_indices.cpp @@ -126,6 +126,17 @@ TEST_CASE("[collection_change] move_over()") { REQUIRE(c.moves.empty()); } + SECTION("is just erase when row + 1 == last_row") { + c.move_over(0, 6); + c.move_over(4, 5); + c.move_over(0, 4); + c.move_over(2, 3); + + REQUIRE_INDICES(c.deletions, 0, 2, 4, 5, 6); + REQUIRE_INDICES(c.insertions, 0); + REQUIRE_MOVES(c, {5, 0}); + } + SECTION("marks the old last row as moved") { c.move_over(5, 8); REQUIRE_MOVES(c, {8, 5});