mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 12:28:18 +00:00
feat: implement a working WinScrolled autocmd
This commit is contained in:
@@ -72,7 +72,6 @@ return {
|
|||||||
'QuickFixCmdPre', -- before :make, :grep etc.
|
'QuickFixCmdPre', -- before :make, :grep etc.
|
||||||
'QuitPre', -- before :quit
|
'QuitPre', -- before :quit
|
||||||
'RemoteReply', -- upon string reception from a remote vim
|
'RemoteReply', -- upon string reception from a remote vim
|
||||||
'Scroll', -- after scrolling
|
|
||||||
'SessionLoadPost', -- after loading a session file
|
'SessionLoadPost', -- after loading a session file
|
||||||
'ShellCmdPost', -- after ":!cmd"
|
'ShellCmdPost', -- after ":!cmd"
|
||||||
'ShellFilterPost', -- after ":1,2!cmd", ":w !cmd", ":r !cmd".
|
'ShellFilterPost', -- after ":1,2!cmd", ":w !cmd", ":r !cmd".
|
||||||
@@ -113,6 +112,7 @@ return {
|
|||||||
'WinEnter', -- after entering a window
|
'WinEnter', -- after entering a window
|
||||||
'WinLeave', -- before leaving a window
|
'WinLeave', -- before leaving a window
|
||||||
'WinNew', -- when entering a new window
|
'WinNew', -- when entering a new window
|
||||||
|
'WinScrolled', -- after scrolling a window
|
||||||
},
|
},
|
||||||
aliases = {
|
aliases = {
|
||||||
BufCreate = 'BufAdd',
|
BufCreate = 'BufAdd',
|
||||||
@@ -124,7 +124,6 @@ return {
|
|||||||
-- syntax file
|
-- syntax file
|
||||||
nvim_specific = {
|
nvim_specific = {
|
||||||
DirChanged=true,
|
DirChanged=true,
|
||||||
Scroll=true,
|
|
||||||
Signal=true,
|
Signal=true,
|
||||||
TabClosed=true,
|
TabClosed=true,
|
||||||
TabNew=true,
|
TabNew=true,
|
||||||
@@ -134,5 +133,6 @@ return {
|
|||||||
UIEnter=true,
|
UIEnter=true,
|
||||||
UILeave=true,
|
UILeave=true,
|
||||||
WinClosed=true,
|
WinClosed=true,
|
||||||
|
WinScrolled=true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -1204,6 +1204,15 @@ struct window_S {
|
|||||||
colnr_T w_skipcol; // starting column when a single line
|
colnr_T w_skipcol; // starting column when a single line
|
||||||
// doesn't fit in the window
|
// 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.
|
// Layout of the window in the screen.
|
||||||
// May need to add "msg_scrolled" to "w_winrow" in rare situations.
|
// May need to add "msg_scrolled" to "w_winrow" in rare situations.
|
||||||
|
@@ -1482,9 +1482,10 @@ static void ins_redraw(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ready && has_event(EVENT_SCROLL)
|
// Trigger Scroll if viewport changed.
|
||||||
&& curwin->w_viewport_invalid) {
|
if (ready && has_event(EVENT_WINSCROLLED)
|
||||||
apply_autocmds(EVENT_SCROLL, NULL, NULL, false, curbuf);
|
&& win_did_scroll(curwin)) {
|
||||||
|
do_autocmd_winscrolled(curwin);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin)
|
if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin)
|
||||||
|
@@ -1195,10 +1195,10 @@ static void normal_check_interrupt(NormalState *s)
|
|||||||
|
|
||||||
static void normal_check_window_scrolled(NormalState *s)
|
static void normal_check_window_scrolled(NormalState *s)
|
||||||
{
|
{
|
||||||
// Trigger Scroll if the window moved.
|
// Trigger Scroll if the viewport changed.
|
||||||
if (!finish_op && has_event(EVENT_SCROLL)
|
if (!finish_op && has_event(EVENT_WINSCROLLED)
|
||||||
&& curwin->w_viewport_invalid) {
|
&& win_did_scroll(curwin)) {
|
||||||
apply_autocmds(EVENT_SCROLL, NULL, NULL, false, curbuf);
|
do_autocmd_winscrolled(curwin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1325,6 +1325,10 @@ static int normal_check(VimState *state)
|
|||||||
if (skip_redraw || exmode_active) {
|
if (skip_redraw || exmode_active) {
|
||||||
skip_redraw = false;
|
skip_redraw = false;
|
||||||
} else if (do_redraw || stuff_empty()) {
|
} 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_cursor_moved(s);
|
||||||
normal_check_text_changed(s);
|
normal_check_text_changed(s);
|
||||||
normal_check_window_scrolled(s);
|
normal_check_window_scrolled(s);
|
||||||
|
@@ -4965,6 +4965,30 @@ void shell_new_columns(void)
|
|||||||
win_reconfig_floats(); // The size of floats might change
|
win_reconfig_floats(); // The size of floats might change
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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".
|
* Save the size of all windows in "gap".
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user