diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2020-11-07 15:13:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-07 15:13:20 +0100 |
commit | e5d83a3bf344a4ab0ef539d70004c2b771e1044a (patch) | |
tree | c4de9a896700ff8a7131ab430cc108d90fd2774a /src/nvim/normal.c | |
parent | da134270d3e9f8a4824b0e0540bf017f7e59b06e (diff) | |
parent | 0fce70252d8e5ccf4cb6f141d1c388966f9f3482 (diff) | |
download | rneovim-e5d83a3bf344a4ab0ef539d70004c2b771e1044a.tar.gz rneovim-e5d83a3bf344a4ab0ef539d70004c2b771e1044a.tar.bz2 rneovim-e5d83a3bf344a4ab0ef539d70004c2b771e1044a.zip |
Merge pull request #13117 from romgrk/add-scroll-events
Implement scroll autocommand
Diffstat (limited to 'src/nvim/normal.c')
-rw-r--r-- | src/nvim/normal.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 11e8d354e4..771ca732f4 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1197,6 +1197,15 @@ static void normal_check_interrupt(NormalState *s) } } +static void normal_check_window_scrolled(NormalState *s) +{ + // Trigger Scroll if the viewport changed. + if (!finish_op && has_event(EVENT_WINSCROLLED) + && win_did_scroll(curwin)) { + do_autocmd_winscrolled(curwin); + } +} + static void normal_check_cursor_moved(NormalState *s) { // Trigger CursorMoved if the cursor moved. @@ -1320,8 +1329,13 @@ static int normal_check(VimState *state) if (skip_redraw || exmode_active) { skip_redraw = false; } else if (do_redraw || stuff_empty()) { + // Need to make sure w_topline and w_leftcol are correct before + // normal_check_window_scrolled() is called. + update_topline(); + normal_check_cursor_moved(s); normal_check_text_changed(s); + normal_check_window_scrolled(s); // Updating diffs from changed() does not always work properly, // esp. updating folds. Do an update just before redrawing if @@ -4111,10 +4125,10 @@ void scroll_redraw(int up, long count) int prev_topfill = curwin->w_topfill; linenr_T prev_lnum = curwin->w_cursor.lnum; - if (up) - scrollup(count, true); - else + bool moved = up ? + scrollup(count, true) : scrolldown(count, true); + if (get_scrolloff_value()) { // Adjust the cursor position for 'scrolloff'. Mark w_topline as // valid, otherwise the screen jumps back at the end of the file. @@ -4144,9 +4158,12 @@ void scroll_redraw(int up, long count) curwin->w_valid |= VALID_TOPLINE; } } - if (curwin->w_cursor.lnum != prev_lnum) + if (curwin->w_cursor.lnum != prev_lnum) { coladvance(curwin->w_curswant); - curwin->w_viewport_invalid = true; + } + if (moved) { + curwin->w_viewport_invalid = true; + } redraw_later(curwin, VALID); } |