diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/auevents.lua | 4 | ||||
-rw-r--r-- | src/nvim/buffer_defs.h | 9 | ||||
-rw-r--r-- | src/nvim/edit.c | 7 | ||||
-rw-r--r-- | src/nvim/normal.c | 12 | ||||
-rw-r--r-- | src/nvim/window.c | 24 |
5 files changed, 47 insertions, 9 deletions
diff --git a/src/nvim/auevents.lua b/src/nvim/auevents.lua index 2d733b0cb7..ea2db41668 100644 --- a/src/nvim/auevents.lua +++ b/src/nvim/auevents.lua @@ -72,7 +72,6 @@ return { 'QuickFixCmdPre', -- before :make, :grep etc. 'QuitPre', -- before :quit 'RemoteReply', -- upon string reception from a remote vim - 'Scroll', -- after scrolling 'SessionLoadPost', -- after loading a session file 'ShellCmdPost', -- after ":!cmd" 'ShellFilterPost', -- after ":1,2!cmd", ":w !cmd", ":r !cmd". @@ -113,6 +112,7 @@ return { 'WinEnter', -- after entering a window 'WinLeave', -- before leaving a window 'WinNew', -- when entering a new window + 'WinScrolled', -- after scrolling a window }, aliases = { BufCreate = 'BufAdd', @@ -124,7 +124,6 @@ return { -- syntax file nvim_specific = { DirChanged=true, - Scroll=true, Signal=true, TabClosed=true, TabNew=true, @@ -134,5 +133,6 @@ return { UIEnter=true, UILeave=true, WinClosed=true, + WinScrolled=true, }, } diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 1223f2bdab..ba71ac6b2b 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -1204,6 +1204,15 @@ struct window_S { colnr_T w_skipcol; // starting column when a single line // doesn't fit in the window + /* + * "w_last_topline" and "w_last_leftcol" are used to determine if + * a Scroll autocommand should be emitted. + */ + linenr_T w_last_topline; ///< last known value for topline + colnr_T w_last_leftcol; ///< last known value for leftcol + int w_last_width; ///< last known value for width + int w_last_height; ///< last known value for height + // // Layout of the window in the screen. // May need to add "msg_scrolled" to "w_winrow" in rare situations. diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 56202177c0..5ea6716c0a 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1482,9 +1482,10 @@ static void ins_redraw( } } - if (ready && has_event(EVENT_SCROLL) - && curwin->w_viewport_invalid) { - apply_autocmds(EVENT_SCROLL, NULL, NULL, false, curbuf); + // Trigger Scroll if viewport changed. + if (ready && has_event(EVENT_WINSCROLLED) + && win_did_scroll(curwin)) { + do_autocmd_winscrolled(curwin); } if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin) diff --git a/src/nvim/normal.c b/src/nvim/normal.c index f6add44f6a..2812297347 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1195,10 +1195,10 @@ static void normal_check_interrupt(NormalState *s) static void normal_check_window_scrolled(NormalState *s) { - // Trigger Scroll if the window moved. - if (!finish_op && has_event(EVENT_SCROLL) - && curwin->w_viewport_invalid) { - apply_autocmds(EVENT_SCROLL, NULL, NULL, false, curbuf); + // Trigger Scroll if the viewport changed. + if (!finish_op && has_event(EVENT_WINSCROLLED) + && win_did_scroll(curwin)) { + do_autocmd_winscrolled(curwin); } } @@ -1325,6 +1325,10 @@ 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); diff --git a/src/nvim/window.c b/src/nvim/window.c index 4931221e7a..bbc039d151 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4966,6 +4966,30 @@ void shell_new_columns(void) } /* + * Check if "wp" has scrolled since last time it was checked + */ +bool win_did_scroll(win_T *wp) +{ + return (curwin->w_last_topline != curwin->w_topline || + curwin->w_last_leftcol != curwin->w_leftcol || + curwin->w_last_width != curwin->w_width || + curwin->w_last_height != curwin->w_height); +} + +/* + * Trigger WinScrolled autocmd + */ +void do_autocmd_winscrolled(win_T *wp) +{ + apply_autocmds(EVENT_WINSCROLLED, NULL, NULL, false, curbuf); + + wp->w_last_topline = wp->w_topline; + wp->w_last_leftcol = wp->w_leftcol; + wp->w_last_width = wp->w_width; + wp->w_last_height = wp->w_height; +} + +/* * Save the size of all windows in "gap". */ void win_size_save(garray_T *gap) |