diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-04-04 12:25:42 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-04-04 12:25:42 +0000 |
| commit | 6cedff8fb26dfd3fe099e71c3d96f8c62f48c73a (patch) | |
| tree | e8623ddd66d7c37cdd7e3e556e43bd10902b0c95 /src | |
| parent | 46c65fea103a93d14e53652ba0a29bdeee6f56f4 (diff) | |
fix some corner cases in Buffer modification
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer.cc | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/buffer.cc b/src/buffer.cc index 060f55c4..4c5241d8 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -191,6 +191,7 @@ void Buffer::check_invariant() const for (auto& line : m_lines) { assert(line.start == start); + assert(line.length() > 0); start += line.length(); } } @@ -264,7 +265,8 @@ void Buffer::erase(const BufferIterator& pos, BufferSize length) Line new_line = { m_lines[pos.line()].start, prefix + suffix }; m_lines.erase(m_lines.begin() + pos.line(), m_lines.begin() + end.line() + 1); - m_lines.insert(m_lines.begin() + pos.line(), new_line); + if (new_line.length()) + m_lines.insert(m_lines.begin() + pos.line(), std::move(new_line)); for (size_t i = pos.line()+1; i < line_count(); ++i) m_lines[i].start -= length; @@ -280,8 +282,12 @@ void Buffer::apply_modification(const Modification& modification) switch (modification.type) { case Modification::Insert: - insert(modification.position, modification.content); + { + BufferIterator pos = modification.position < end() ? + modification.position : end(); + insert(pos, modification.content); break; + } case Modification::Erase: { size_t size = modification.content.size(); |
