From 5d9f3b7f3f38fd7153edda2992e77114d6e1dd83 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 10 Dec 2016 13:33:42 +0000 Subject: [PATCH] Ensure the line is correctly clamped in scroll_window Seems like the previous implementation was not always doing that correctly, so just use an obviously correct method. Fixes #951 --- src/input_handler.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/input_handler.cc b/src/input_handler.cc index fae254fb..7d3ce050 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -1515,9 +1515,11 @@ void scroll_window(Context& context, LineCount offset) SelectionList& selections = context.selections(); const BufferCoord cursor = selections.main().cursor(); + auto line = clamp(cursor.line, win_pos.line + scrolloff.line, + win_pos.line + win_dim.line - 1 - scrolloff.line); + line = clamp(line, 0_line, line_count-1); + using std::min; using std::max; - auto line = clamp(cursor.line, max(0_line, win_pos.line + scrolloff.line), - min(line_count-1, win_pos.line + win_dim.line - 1 - scrolloff.line)); // This is not exactly a clamp, and must be done in this order as // byte_count_to could return line length auto col = min(max(cursor.column, buffer[line].byte_count_to(win_pos.column)),