From b1115f7469a42184fce26db6ca5756f1e835185d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 10 Nov 2017 21:17:05 +0800 Subject: [PATCH] Wrap: fix scrolling to keep cursor visible logic --- src/highlighters.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index 8da4d6bd..e339d441 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -798,10 +798,11 @@ struct WrapHighlighter : Highlighter win_line += wrap_count + 1; // scroll window to keep cursor visible, and update range as lines gets removed - while (setup.window_pos.line < cursor.line and + while (buf_line >= cursor.line and setup.window_pos.line < cursor.line and cursor.line + setup.scroll_offset.line >= setup.window_pos.line + setup.window_range.line) { - auto removed_lines = 1 + line_wrap_count(setup.window_pos.line++, indent); + auto removed_lines = std::min(context.window().dimensions().line, + 1 + line_wrap_count(setup.window_pos.line++, indent)); setup.cursor_pos.line -= removed_lines; win_line -= removed_lines; // removed one line from the range, added removed_lines potential ones