summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-05-24 02:35:08 +0100
committerMaxime Coste <frrrwww@gmail.com>2014-05-24 02:35:08 +0100
commita6de024c1fb9b1bcc04d9cea48c10131bb2f4168 (patch)
tree4dfa4785bce64ecda2478e724cfa295accfe8619 /src
parent1544a006c9cde5c3fd19ee763dd9d39ac2633f6d (diff)
Fix Modification
Diffstat (limited to 'src')
-rw-r--r--src/modification.cc6
-rw-r--r--src/unit_tests.cc13
2 files changed, 19 insertions, 0 deletions
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<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)
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<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",