From 69789d4793f91daab4f489147338ed593f34093d Mon Sep 17 00:00:00 2001
From: Maxime Coste <mawww@kakoune.org>
Date: Sun, 1 Jan 2017 15:33:46 +0000
Subject: [PATCH] When inserting at the end, store the next line as end pos in
 the change

---
 src/buffer.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/buffer.cc b/src/buffer.cc
index 99ec68f1..00506c7f 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -484,7 +484,8 @@ BufferCoord Buffer::do_insert(BufferCoord pos, StringView content)
                    std::make_move_iterator(new_lines.end()));
 
     const LineCount last_line = pos.line + new_lines.size() - 1;
-    const BufferCoord end = BufferCoord{ last_line, m_lines[last_line].length() - suffix.length() };
+    const auto end = at_end ? line_count()
+                            : BufferCoord{ last_line, m_lines[last_line].length() - suffix.length() };
 
     m_changes.push_back({ Change::Insert, at_end, pos, end });
     return pos;