diff --git a/src/buffer.cc b/src/buffer.cc index d7882b63..3e4c7e5e 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -166,7 +166,12 @@ void Buffer::update_display_name() BufferIterator Buffer::iterator_at(BufferCoord coord) const { - return is_end(coord) ? end() : BufferIterator(*this, clamp(coord)); + // Tolerate one past the end of line + if (not is_end(coord) and coord.column == m_lines[coord.line].length()) + coord = coord.line+1; + + kak_assert(is_valid(coord)); + return {*this, coord}; } BufferCoord Buffer::clamp(BufferCoord coord) const diff --git a/src/window.cc b/src/window.cc index e3630ad8..ff43d9fc 100644 --- a/src/window.cc +++ b/src/window.cc @@ -132,11 +132,11 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context) if (buffer_line >= buffer().line_count()) break; auto beg_byte = get_byte_to_column(buffer(), tabstop, {buffer_line, m_position.column}); - auto end_byte = get_byte_to_column(buffer(), tabstop, {buffer_line, m_position.column + m_range.column}); - auto end_coord = setup.full_lines or end_byte == buffer()[buffer_line].length() ? - buffer_line+1 : BufferCoord{buffer_line, end_byte}; + auto end_byte = setup.full_lines ? + buffer()[buffer_line].length() + : get_byte_to_column(buffer(), tabstop, {buffer_line, m_position.column + m_range.column}); - lines.emplace_back(AtomList{ {buffer(), {buffer_line, beg_byte}, end_coord} }); + lines.emplace_back(AtomList{ {buffer(), {buffer_line, beg_byte}, {buffer_line, end_byte}} }); } m_display_buffer.compute_range();