summaryrefslogtreecommitdiff
path: root/src/line_modification.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-06-11 12:01:40 +0100
committerMaxime Coste <mawww@kakoune.org>2017-06-11 12:01:40 +0100
commit63a791d65118bf37606db36ee12287e890d528ea (patch)
tree3812cb83f684486484b7ab099d768e98e7fca982 /src/line_modification.cc
parentb4647a16dda162c78fd7628f1ebb7325e95ba38c (diff)
Fix the Buffer::end() madness
Until now, buffer had multiple recognized end coordinates, either { line_count, 0 } or { line_count - 1, line[line_count - 1].length }. Now the only correct end coord is { line_count, 0 }, removing the need for various special cases.
Diffstat (limited to 'src/line_modification.cc')
-rw-r--r--src/line_modification.cc15
1 files changed, 2 insertions, 13 deletions
diff --git a/src/line_modification.cc b/src/line_modification.cc
index 3d6617dd..df2b9cbc 100644
--- a/src/line_modification.cc
+++ b/src/line_modification.cc
@@ -10,22 +10,11 @@ static LineModification make_line_modif(const Buffer::Change& change)
{
LineCount num_added = 0, num_removed = 0;
if (change.type == Buffer::Change::Insert)
- {
num_added = change.end.line - change.begin.line;
- // inserted a new line at buffer end but end coord is on same line
- if (change.at_end and change.end.column != 0)
- ++num_added;
- }
else
- {
num_removed = change.end.line - change.begin.line;
- // removed last line, but end coord is on same line
- if (change.at_end and change.end.column != 0)
- ++num_removed;
- }
// modified a line
- if (not change.at_end and
- (change.begin.column != 0 or change.end.column != 0))
+ if ((change.begin.column != 0 or change.end.column != 0))
{
++num_removed;
++num_added;
@@ -116,7 +105,7 @@ UnitTest test_line_modifications{[]()
{
Buffer buffer("test", Buffer::Flags::None, "line 1\nline 2\n");
auto ts = buffer.timestamp();
- buffer.insert({1, 7}, "line 3");
+ buffer.insert({2, 0}, "line 3");
auto modifs = compute_line_modifications(buffer, ts);
kak_assert(modifs.size() == 1 and modifs[0] == LineModification{ 2, 2, 0, 1 });