From 36e4dacdf5e33b9d92ea59124ef67a040b5392cb Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 28 Jun 2012 14:26:01 +0200 Subject: [PATCH] Fix BufferIterator::on_erase and tweak Buffer --- src/buffer.cc | 3 ++- src/buffer_iterator.inl.hh | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index 30cf6d38..4c29837a 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -152,7 +152,7 @@ void Buffer::end_undo_group() if (m_current_undo_group.empty()) return; - m_history.push_back(m_current_undo_group); + m_history.push_back(std::move(m_current_undo_group)); m_history_cursor = m_history.end(); m_current_undo_group.clear(); @@ -277,6 +277,7 @@ void Buffer::insert(const BufferIterator& pos, const String& content) void Buffer::erase(const BufferIterator& pos, BufferSize length) { BufferIterator end = pos + length; + assert(end.is_valid()); String prefix = m_lines[pos.line()].content.substr(0, pos.column()); String suffix = m_lines[end.line()].content.substr(end.column()); Line new_line = { m_lines[pos.line()].start, prefix + suffix }; diff --git a/src/buffer_iterator.inl.hh b/src/buffer_iterator.inl.hh index bcb83ab0..2ae412e7 100644 --- a/src/buffer_iterator.inl.hh +++ b/src/buffer_iterator.inl.hh @@ -32,6 +32,7 @@ inline BufferIterator& BufferIterator::operator=(const BufferIterator& iterator) { m_buffer = iterator.m_buffer; m_coord = iterator.m_coord; + assert(is_valid()); return *this; } @@ -90,18 +91,17 @@ inline void BufferIterator::on_erase(const BufferCoord& begin, if (m_coord < begin) return; - BufferCoord measure; - measure.line = end.line - begin.line; - measure.column = end.column - (measure.line == 0 ? begin.column : 0); if (m_coord <= end) m_coord = begin; else { - m_coord.line -= measure.line; - if (measure.line > 0 and begin.line == m_coord.line) - m_coord.column += begin.column; if (end.line == m_coord.line) - m_coord.column -= measure.column; + { + m_coord.line = begin.line; + m_coord.column = begin.column + m_coord.column - end.column; + } + else + m_coord.line -= end.line - begin.line; } if (is_end())