summaryrefslogtreecommitdiff
path: root/src/buffer.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-03-17 12:36:49 +0000
committerMaxime Coste <frrrwww@gmail.com>2016-03-17 12:38:09 +0000
commit38f146d84963e04cddb3e83b7f5f06c630bd5cd2 (patch)
treefa7434d5db9a5d17ecc391b5742c3670cb13eccf /src/buffer.cc
parentd277ef6d6c38ed35b46b20215aaf1c7b2621f1e7 (diff)
Fix another bug in Buffer::replace implementation
Diffstat (limited to 'src/buffer.cc')
-rw-r--r--src/buffer.cc16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index d96b727b..cee8870a 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -415,21 +415,14 @@ void Buffer::apply_modification(const Modification& modification)
ByteCoord coord = modification.coord;
kak_assert(is_valid(coord));
- // in modifications, end coords should be {line_count(), 0}
- kak_assert((m_lines.empty() and coord == ByteCoord{0,0} ) or
- coord != ByteCoord(line_count()-1, m_lines.back().length()));
-
switch (modification.type)
{
case Modification::Insert:
- {
do_insert(coord, content);
break;
- }
case Modification::Erase:
{
- ByteCount count = content.length();
- ByteCoord end = advance(coord, count);
+ auto end = advance(coord, content.length());
kak_assert(string(coord, end) == content);
do_erase(coord, end);
break;
@@ -453,7 +446,7 @@ ByteCoord Buffer::insert(ByteCoord pos, StringView content)
// for undo and redo purpose it is better to use one past last line rather
// than one past last char coord.
- auto coord = is_end(pos) ? ByteCoord{line_count()} : pos;
+ auto coord = is_end(pos) ? line_count() : pos;
if (not (m_flags & Flags::NoUndo))
m_current_undo_group.emplace_back(Modification::Insert, coord, real_content);
return do_insert(pos, real_content->strview());
@@ -489,7 +482,10 @@ ByteCoord Buffer::replace(ByteCoord begin, ByteCoord end, StringView content)
else
real_content = intern(content);
- auto coord = is_end(pos) ? ByteCoord{line_count()} : pos;
+ bool last_char_is_eol = not (m_lines.empty() or
+ m_lines.back().empty() or
+ m_lines.back().back() != '\n');
+ auto coord = is_end(pos) and last_char_is_eol ? line_count() : pos;
if (not (m_flags & Flags::NoUndo))
m_current_undo_group.emplace_back(Modification::Insert, coord, real_content);
return do_insert(pos, real_content->strview());