Fix Modification

This commit is contained in:
Maxime Coste 2014-05-24 02:35:08 +01:00
parent 1544a006c9
commit a6de024c1f
2 changed files with 19 additions and 0 deletions

View File

@ -165,6 +165,12 @@ std::vector<Modification> compute_modifications(memoryview<Buffer::Change> 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)

View File

@ -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<Buffer::Change> 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",