summaryrefslogtreecommitdiff
path: root/src/buffer.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-06-06 20:02:20 +0200
committerMaxime Coste <frrrwww@gmail.com>2013-06-06 20:02:20 +0200
commit7306f6b33b7da0cc48f975e0c3d95cb8f66d27d5 (patch)
tree5af0e20c53b462de39a1a43685207a9b8179921d /src/buffer.cc
parent59b996be7556495e151ace6441a10ab8e381c761 (diff)
Buffer: always use {line_count(), 0} as end in Modifications
Diffstat (limited to 'src/buffer.cc')
-rw-r--r--src/buffer.cc14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index f46049de..a7e26faa 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -526,14 +526,11 @@ BufferCoord Buffer::do_erase(const BufferCoord& begin, const BufferCoord& end)
void Buffer::apply_modification(const Modification& modification)
{
const String& content = modification.content;
- BufferCoord coord = modification.coord;
-
- // this may happen when a modification applied at the
- // end of the buffer has been inverted for an undo.
- if (coord.line < line_count()-1 and coord.column == m_lines[coord.line].length())
- coord = { coord.line + 1, 0 };
+ const BufferCoord& coord = modification.coord;
kak_assert(is_valid(coord));
+ // in modifications, end coords should be {line_count(), 0}
+ kak_assert(coord != BufferCoord(line_count()-1, m_lines.back().length()));
switch (modification.type)
{
case Modification::Insert:
@@ -563,8 +560,11 @@ BufferIterator Buffer::insert(const BufferIterator& pos, String content)
if (pos == end() and content.back() != '\n')
content += '\n';
+ // for undo and redo purpose it is better to use one past last line rather
+ // than one past last char coord.
+ auto coord = pos == end() ? BufferCoord{line_count()} : pos.coord();
if (not (m_flags & Flags::NoUndo))
- m_current_undo_group.emplace_back(Modification::Insert, pos.coord(), content);
+ m_current_undo_group.emplace_back(Modification::Insert, coord, content);
return {*this, do_insert(pos.coord(), content)};
}