mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
feat: implement a working WinScrolled autocmd
This commit is contained in:
parent
d2a38dab80
commit
bc21843228
@ -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,
|
||||
},
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -4965,6 +4965,30 @@ void shell_new_columns(void)
|
||||
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".
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user