Clean up old move info even when the row being deleted is the last one

This commit is contained in:
Thomas Goyne 2016-04-26 14:45:56 -07:00
parent 3218740fd9
commit 4df552ba2d
2 changed files with 20 additions and 2 deletions

View File

@ -249,8 +249,13 @@ void CollectionChangeBuilder::move_over(size_t row_ndx, size_t last_row, bool tr
REALM_ASSERT(row_ndx <= last_row);
REALM_ASSERT(insertions.empty() || prev(insertions.end())->second - 1 <= last_row);
REALM_ASSERT(modifications.empty() || prev(modifications.end())->second - 1 <= last_row);
if (track_moves && row_ndx == last_row) {
erase(row_ndx);
if (row_ndx == last_row) {
auto shifted_from = insertions.erase_or_unshift(row_ndx);
if (shifted_from != IndexSet::npos)
deletions.add_shifted(shifted_from);
modifications.remove(row_ndx);
m_move_mapping.erase(row_ndx);
return;
}

View File

@ -124,7 +124,10 @@ TEST_CASE("[collection_change] move_over()") {
SECTION("is just erase when row == last_row") {
c.move_over(10, 10);
c.parse_complete();
REQUIRE_INDICES(c.deletions, 10);
REQUIRE(c.insertions.empty());
REQUIRE(c.moves.empty());
}
@ -189,6 +192,16 @@ TEST_CASE("[collection_change] move_over()") {
REQUIRE_MOVES(c, {10, 5});
}
SECTION("removes moves to the row when row == last_row") {
c.move_over(0, 1);
c.move_over(0, 0);
c.parse_complete();
REQUIRE_INDICES(c.deletions, 0, 1);
REQUIRE(c.insertions.empty());
REQUIRE(c.moves.empty());
}
SECTION("is not shifted by previous calls to move_over()") {
c.move_over(5, 10);
c.move_over(6, 9);