Fix marking deletions when chaining move_last_over()
This commit is contained in:
parent
51edc6909c
commit
0a3158ce74
|
@ -292,8 +292,17 @@ void CollectionChangeBuilder::move_over(size_t row_ndx, size_t last_row)
|
|||
move.to = row_ndx;
|
||||
updated_existing_move = true;
|
||||
|
||||
insertions.erase_at(last_row);
|
||||
insertions.insert_at(row_ndx);
|
||||
if (!insertions.empty()) {
|
||||
REALM_ASSERT(std::prev(insertions.end())->second - 1 <= last_row);
|
||||
insertions.remove(last_row);
|
||||
}
|
||||
|
||||
// Don't mark the moved-over row as deleted if it was a new insertion
|
||||
if (!insertions.contains(row_ndx)) {
|
||||
deletions.add_shifted(insertions.unshift(row_ndx));
|
||||
insertions.add(row_ndx);
|
||||
}
|
||||
|
||||
// Because this is a move, the unshifted source row has already been marked as deleted
|
||||
}
|
||||
|
||||
|
@ -312,6 +321,7 @@ void CollectionChangeBuilder::move_over(size_t row_ndx, size_t last_row)
|
|||
deletions.add_shifted(insertions.unshift(row_ndx));
|
||||
insertions.add(row_ndx);
|
||||
}
|
||||
verify();
|
||||
}
|
||||
|
||||
void CollectionChangeBuilder::verify()
|
||||
|
|
|
@ -185,6 +185,15 @@ TEST_CASE("[collection_change] move_over()") {
|
|||
REQUIRE_INDICES(c.insertions, 5, 6);
|
||||
REQUIRE_MOVES(c, {10, 5}, {9, 6});
|
||||
}
|
||||
|
||||
SECTION("marks the moved-over row as deleted when chaining moves") {
|
||||
c.move_over(5, 10);
|
||||
c.move_over(0, 5);
|
||||
|
||||
REQUIRE_INDICES(c.deletions, 0, 5, 10);
|
||||
REQUIRE_INDICES(c.insertions, 0);
|
||||
REQUIRE_MOVES(c, {10, 0});
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[collection_change] clear()") {
|
||||
|
|
Loading…
Reference in New Issue