diff options
-rw-r--r-- | src/nvim/auevents.lua | 2 | ||||
-rw-r--r-- | src/nvim/buffer_defs.h | 3 | ||||
-rw-r--r-- | src/nvim/edit.c | 25 | ||||
-rw-r--r-- | src/nvim/normal.c | 18 |
4 files changed, 48 insertions, 0 deletions
diff --git a/src/nvim/auevents.lua b/src/nvim/auevents.lua index 4391d997a7..2d733b0cb7 100644 --- a/src/nvim/auevents.lua +++ b/src/nvim/auevents.lua @@ -72,6 +72,7 @@ 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". @@ -123,6 +124,7 @@ return { -- syntax file nvim_specific = { DirChanged=true, + Scroll=true, Signal=true, TabClosed=true, TabNew=true, diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 1223f2bdab..546054bb19 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -1204,6 +1204,9 @@ struct window_S { colnr_T w_skipcol; // starting column when a single line // doesn't fit in the window + linenr_T w_last_topline; ///< last known value for topline + colnr_T w_last_leftcol; ///< last known value for leftcol + // // 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 de2346a9d8..447f922767 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1482,6 +1482,31 @@ static void ins_redraw( } } + if (ready && has_event(EVENT_SCROLL) + && (curwin->w_last_topline != curwin->w_topline || + curwin->w_last_leftcol != curwin->w_leftcol)) { + + // XXX is the buf changedtick thing necessary? + // XXX apply_autocmds vs ins_apply_autocmds? + // XXX why can't we re-use normal_check_window_scrolled()? + + aco_save_T aco; + varnumber_T tick = buf_get_changedtick(curbuf); + + // save and restore curwin and curbuf, in case the autocmd changes them + aucmd_prepbuf(&aco, curbuf); + apply_autocmds(EVENT_SCROLL, NULL, NULL, false, curbuf); + aucmd_restbuf(&aco); + curbuf->b_last_changedtick_pum = buf_get_changedtick(curbuf); + if (tick != buf_get_changedtick(curbuf)) { // see ins_apply_autocmds() + u_save(curwin->w_cursor.lnum, + (linenr_T)(curwin->w_cursor.lnum + 1)); + } + + curwin->w_last_topline = curwin->w_topline; + curwin->w_last_leftcol = curwin->w_leftcol; + } + if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin) && conceal_cursor_moved) { redrawWinline(curwin, curwin->w_cursor.lnum); diff --git a/src/nvim/normal.c b/src/nvim/normal.c index a51aa0dc07..eb15204c63 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1193,6 +1193,22 @@ static void normal_check_interrupt(NormalState *s) } } +static void normal_check_window_scrolled(NormalState *s) +{ + // XXX why is has_event necessary? + + // Trigger Scroll if the window moved. + if (!finish_op && has_event(EVENT_SCROLL) + && (curwin->w_last_topline != curwin->w_topline || + curwin->w_last_leftcol != curwin->w_leftcol)) { + + apply_autocmds(EVENT_SCROLL, NULL, NULL, false, curbuf); + + curwin->w_last_topline = curwin->w_topline; + curwin->w_last_leftcol = curwin->w_leftcol; + } +} + static void normal_check_cursor_moved(NormalState *s) { // Trigger CursorMoved if the cursor moved. @@ -1279,6 +1295,7 @@ static void normal_redraw(NormalState *s) xfree(p); } + // show fileinfo after redraw if (need_fileinfo && !shortmess(SHM_FILEINFO)) { fileinfo(false, true, false); @@ -1318,6 +1335,7 @@ static int normal_check(VimState *state) } else if (do_redraw || stuff_empty()) { 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 |