diff --git a/src/collection_notifications.cpp b/src/collection_notifications.cpp index 59c835ad..0457211d 100644 --- a/src/collection_notifications.cpp +++ b/src/collection_notifications.cpp @@ -94,6 +94,8 @@ void CollectionChangeBuilder::merge(CollectionChangeBuilder&& c) return old.to == m.from; }); if (it != c.moves.end()) { + if (modifications.contains(it->from)) + c.modifications.add(it->to); old.to = it->to; *it = c.moves.back(); c.moves.pop_back(); diff --git a/src/impl/list_notifier.cpp b/src/impl/list_notifier.cpp index 5d69f4e3..aba0244a 100644 --- a/src/impl/list_notifier.cpp +++ b/src/impl/list_notifier.cpp @@ -96,17 +96,20 @@ void ListNotifier::run() return; } - m_change.moves.erase(remove_if(begin(m_change.moves), end(m_change.moves), - [&](auto move) { return m_change.modifications.contains(move.to); }), - end(m_change.moves)); - for (size_t i = 0; i < m_lv->size(); ++i) { - if (m_change.insertions.contains(i) || m_change.modifications.contains(i)) + if (m_change.modifications.contains(i)) continue; if (m_info->row_did_change(m_lv->get_target_table(), m_lv->get(i).get_index())) m_change.modifications.add(i); } + for (auto const& move : m_change.moves) { + if (m_change.modifications.contains(move.to)) + continue; + if (m_info->row_did_change(m_lv->get_target_table(), m_lv->get(move.to).get_index())) + m_change.modifications.add(move.to); + } + m_prev_size = m_lv->size(); } diff --git a/tests/collection_change_indices.cpp b/tests/collection_change_indices.cpp index 2fac5fa9..4c8dd2e6 100644 --- a/tests/collection_change_indices.cpp +++ b/tests/collection_change_indices.cpp @@ -861,6 +861,14 @@ TEST_CASE("[collection_change] merge()") { REQUIRE_MOVES(c, {1, 3}); } + SECTION("updates the row modified for chained moves") { + c = {{}, {}, {1}, {}}; + c.merge({{}, {}, {}, {{1, 3}}}); + c.merge({{}, {}, {}, {{3, 5}}}); + REQUIRE_INDICES(c.modifications, 5); + REQUIRE_MOVES(c, {1, 5}); + } + SECTION("updates the row inserted for moves of previously new rows") { c = {{}, {1}, {}, {}}; c.merge({{}, {}, {}, {{1, 3}}}); diff --git a/tests/list.cpp b/tests/list.cpp index 7686c4ea..5b38a4d4 100644 --- a/tests/list.cpp +++ b/tests/list.cpp @@ -219,6 +219,28 @@ TEST_CASE("list") { REQUIRE_INDICES(changes[i].modifications, 2); } } + + SECTION("modifications are reported for rows that are moved and then moved back in a second transaction") { + auto token = require_change(); + + r->begin_transaction(); + lv->get(5).set_int(0, 10); + lv->get(1).set_int(0, 10); + lv->move(5, 8); + lv->move(1, 2); + r->commit_transaction(); + + coordinator.on_change(); + + write([&]{ + lv->move(8, 5); + }); + + REQUIRE_INDICES(change.deletions, 1); + REQUIRE_INDICES(change.insertions, 2); + REQUIRE_INDICES(change.modifications, 5); + REQUIRE_MOVES(change, {1, 2}); + } } SECTION("sorted add_notification_block()") {