diff --git a/src/modification.cc b/src/modification.cc index 2539ea3a..876463f1 100644 --- a/src/modification.cc +++ b/src/modification.cc @@ -165,6 +165,12 @@ std::vector compute_modifications(memoryview chang } ByteCoord num_removed_from_added = std::min(num_removed, num_added_after_pos); modif.num_added -= num_removed_from_added; + + if (change.begin.line == modif.new_coord.line) + modif.num_added.column += change.begin.column - modif.new_coord.column; + else + modif.num_added.column += change.begin.column; + modif.num_removed += num_removed - num_removed_from_added; for (auto it = next; it != res.end(); ++it) diff --git a/src/unit_tests.cc b/src/unit_tests.cc index 6bae7a80..36c885bd 100644 --- a/src/unit_tests.cc +++ b/src/unit_tests.cc @@ -204,6 +204,19 @@ void test_modification() kak_assert(modif.num_added == ByteCoord{0 COMMA 0}); kak_assert(modif.num_removed == ByteCoord{1 COMMA 0}); } + { + std::vector change = { + { Buffer::Change::Insert, {1, 10}, {2, 0}, false }, + { Buffer::Change::Erase, {1, 20}, {2, 10}, false }, + }; + auto modifs = compute_modifications(change); + kak_assert(modifs.size() == 1); + auto& modif = modifs[0]; + kak_assert(modif.old_coord == ByteCoord{1 COMMA 10}); + kak_assert(modif.new_coord == ByteCoord{1 COMMA 10}); + kak_assert(modif.num_added == ByteCoord{0 COMMA 10}); + kak_assert(modif.num_removed == ByteCoord{0 COMMA 10}); + } Buffer buffer("test", Buffer::Flags::None, { "tchou mutch\n",