mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
implement scroll autocommand
This commit is contained in:
parent
0f590ae2a8
commit
b83d8223ff
@ -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,
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user