diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-11-07 23:56:24 +0800 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-11-07 23:56:24 +0800 |
| commit | d45f16b6c813842690e06ca70102be345ce80596 (patch) | |
| tree | df825e39074d9777e19de309bec229012c7c17ff /src/buffer.cc | |
| parent | 80ce768994c75952b75cf31bef3c67871e5e5723 (diff) | |
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.
Diffstat (limited to 'src/buffer.cc')
| -rw-r--r-- | src/buffer.cc | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/buffer.cc b/src/buffer.cc index 9650ee20..0ffdb9ae 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; |
