From d45f16b6c813842690e06ca70102be345ce80596 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 7 Nov 2017 23:56:24 +0800 Subject: [PATCH] Buffer: change clamp logic to preserve ordering clamp could change ordering between a coordinate past the end. Say in a buffer with 1 line of 2 char: {0, 1} was clamped to {0, 1} {1, 0} was clamped to {0, 0} That was reversing their ordering, and might be the root cause of the bug lurking in undo range computation. --- src/buffer.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/buffer.cc b/src/buffer.cc index 9650ee20b..0ffdb9aee 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -172,7 +172,9 @@ BufferIterator Buffer::iterator_at(BufferCoord coord) const BufferCoord Buffer::clamp(BufferCoord coord) const { - coord.line = Kakoune::clamp(coord.line, 0_line, line_count() - 1); + if (coord > back_coord()) + coord = back_coord(); + kak_assert(coord.line >= 0 and coord.line < line_count()); ByteCount max_col = std::max(0_byte, m_lines[coord.line].length() - 1); coord.column = Kakoune::clamp(coord.column, 0_byte, max_col); return coord;