diff --git a/src/buffer.cc b/src/buffer.cc index 81804c79..0b0dca1e 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -351,7 +351,9 @@ void Buffer::apply_modification(const Modification& modification) kak_assert(is_valid(coord)); // in modifications, end coords should be {line_count(), 0} - kak_assert(coord != ByteCoord(line_count()-1, m_lines.back().length())); + 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: diff --git a/src/buffer.inl.hh b/src/buffer.inl.hh index 0e82b7a9..7b09f1a4 100644 --- a/src/buffer.inl.hh +++ b/src/buffer.inl.hh @@ -68,7 +68,7 @@ inline bool Buffer::is_valid(ByteCoord c) const inline bool Buffer::is_end(ByteCoord c) const { - return c >= ByteCoord{line_count() - 1, m_lines.back().length()}; + return c >= end_coord(); } inline BufferIterator Buffer::begin() const @@ -78,9 +78,7 @@ inline BufferIterator Buffer::begin() const inline BufferIterator Buffer::end() const { - if (m_lines.empty()) - return BufferIterator(*this, { 0_line, 0 }); - return BufferIterator(*this, { line_count() - 1, m_lines.back().length() }); + return BufferIterator{*this, end_coord()}; } [[gnu::always_inline]] @@ -107,6 +105,8 @@ inline ByteCoord Buffer::back_coord() const inline ByteCoord Buffer::end_coord() const { + if (m_lines.empty()) + return { 0_line, 0 }; return { line_count() - 1, m_lines.back().length() }; }