summaryrefslogtreecommitdiffstats
path: root/src/autocmd.c
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2022-04-08 15:18:45 +0100
committerBram Moolenaar <Bram@vim.org>2022-04-08 15:18:45 +0100
commit0937182d49fa8db50cec42785f22f1031760a0bd (patch)
treea41ab36fcbeb5b2f0bc91ce36b2d056af2ec2491 /src/autocmd.c
parent18ee0f603ebd3c091f6d2ab88e652fda32821048 (diff)
patch 8.2.4713: plugins cannot track text scrollingv8.2.4713
Problem: Plugins cannot track text scrolling. Solution: Add the WinScrolled event. (closes #10102)
Diffstat (limited to 'src/autocmd.c')
-rw-r--r--src/autocmd.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/autocmd.c b/src/autocmd.c
index 7eb08c85b9..a0065decba 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -190,6 +190,7 @@ static struct event_name
{"WinClosed", EVENT_WINCLOSED},
{"WinEnter", EVENT_WINENTER},
{"WinLeave", EVENT_WINLEAVE},
+ {"WinScrolled", EVENT_WINSCROLLED},
{"VimResized", EVENT_VIMRESIZED},
{"TextYankPost", EVENT_TEXTYANKPOST},
{"VimSuspend", EVENT_VIMSUSPEND},
@@ -1251,6 +1252,15 @@ do_autocmd_event(
vim_free(rettv.vval.v_string);
}
#endif
+ // Initialize the fields checked by the WinScrolled trigger to
+ // stop it from firing right after the first autocmd is defined.
+ if (event == EVENT_WINSCROLLED && !has_winscrolled())
+ {
+ 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;
+ }
if (is_buflocal)
{
@@ -1783,6 +1793,15 @@ trigger_cursorhold(void)
}
/*
+ * Return TRUE when there is a WinScrolled autocommand defined.
+ */
+ int
+has_winscrolled(void)
+{
+ return (first_autopat[(int)EVENT_WINSCROLLED] != NULL);
+}
+
+/*
* Return TRUE when there is a CursorMoved autocommand defined.
*/
int
@@ -2078,7 +2097,8 @@ apply_autocmds_group(
|| event == EVENT_DIRCHANGEDPRE
|| event == EVENT_MODECHANGED
|| event == EVENT_USER
- || event == EVENT_WINCLOSED)
+ || event == EVENT_WINCLOSED
+ || event == EVENT_WINSCROLLED)
{
fname = vim_strsave(fname);
autocmd_fname_full = TRUE; // don't expand it later