From 7306f6b33b7da0cc48f975e0c3d95cb8f66d27d5 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 6 Jun 2013 20:02:20 +0200 Subject: [PATCH] Buffer: always use {line_count(), 0} as end in Modifications --- src/buffer.cc | 14 +++++++------- 1 file 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)}; }