From ad9ad7e603fe115c2ef6ee9a4731af9c2014ac11 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 21 May 2017 08:24:44 +0100 Subject: [PATCH] Fix vertical movement with tabstops Fixes #1388 --- src/buffer.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index 6d9321d6..e5527693 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -186,11 +186,10 @@ BufferCoord Buffer::offset_coord(BufferCoord coord, CharCount offset, ColumnCoun BufferCoordAndTarget Buffer::offset_coord(BufferCoordAndTarget coord, LineCount offset, ColumnCount tabstop) { - auto column = coord.target == -1 ? get_column(*this, tabstop, coord) : coord.target; - auto line = Kakoune::clamp(coord.line + offset, 0_line, line_count()-1); - StringView content = m_lines[line]; - - auto final_column = std::max(0_col, std::min(column, content.column_length() - 2)); + const auto column = coord.target == -1 ? get_column(*this, tabstop, coord) : coord.target; + const auto line = Kakoune::clamp(coord.line + offset, 0_line, line_count()-1); + const auto max_column = get_column(*this, tabstop, {line, m_lines[line].length()-1}); + const auto final_column = std::max(0_col, std::min(column, max_column - 1)); return {line, get_byte_to_column(*this, tabstop, {line, final_column}), column}; }