From e6c4bed42b73745681b12cac0178558fc380f36c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 15 Jun 2017 17:25:37 +0100 Subject: [PATCH] Go back to window lines ending at one past the end of the buffer line Change Buffer::iterator_at so that this case is tolerated, and fixes the coord to next line start instead of clamping to last line char. --- src/buffer.cc | 7 ++++++- src/window.cc | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) 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();