Skip to content

Commit 3fc84dc

Browse files
zeertzjqbrammool
authored andcommitted
patch 9.0.1025: WinScrolled is not triggered when filler lines change
Problem: WinScrolled is not triggered when filler lines change. Solution: Add "topfill" to the values that WinScrolled triggers on. (closes #11668)
1 parent 86b4816 commit 3fc84dc

File tree

5 files changed

+111
-15
lines changed

5 files changed

+111
-15
lines changed

runtime/doc/windows.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,9 @@ The information provided by |WinScrolled| is a dictionary for each window that
657657
has changes, using the window ID as the key, and a total count of the changes
658658
with the key "all". Example value for |v:event| (|Vim9| syntax):
659659
{
660-
all: {width: 0, height: 2, leftcol: 0, topline: 1, skipcol: 0},
661-
1003: {width: 0, height: -1, leftcol: 0, topline: 0, skipcol: 0},
662-
1006: {width: 0, height: 1, leftcol: 0, topline: 1, skipcol: 0},
660+
all: {width: 0, height: 2, leftcol: 0, skipcol: 0, topline: 1, topfill: 0},
661+
1003: {width: 0, height: -1, leftcol: 0, skipcol: 0, topline: 0, topfill: 0},
662+
1006: {width: 0, height: 1, leftcol: 0, skipcol: 0, topline: 1, topfill: 0},
663663
}
664664

665665
Note that the "all" entry has the absolute values of the individual windows

src/structs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3618,6 +3618,9 @@ struct window_S
36183618

36193619
// five fields that are only used when there is a WinScrolled autocommand
36203620
linenr_T w_last_topline; // last known value for w_topline
3621+
#ifdef FEAT_DIFF
3622+
linenr_T w_last_topfill; // last known value for w_topfill
3623+
#endif
36213624
colnr_T w_last_leftcol; // last known value for w_leftcol
36223625
colnr_T w_last_skipcol; // last known value for w_skipcol
36233626
int w_last_width; // last known value for w_width

src/testdir/test_autocmd.vim

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ func Test_WinScrolled()
393393

394394
let event = readfile('XscrollEvent')[0]->json_decode()
395395
call assert_equal({
396-
\ 'all': {'leftcol': 1, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0},
397-
\ '1000': {'leftcol': -1, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0}
396+
\ 'all': {'leftcol': 1, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
397+
\ '1000': {'leftcol': -1, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}
398398
\ }, event)
399399

400400
" Scroll up/down in Normal mode.
@@ -403,8 +403,8 @@ func Test_WinScrolled()
403403

404404
let event = readfile('XscrollEvent')[0]->json_decode()
405405
call assert_equal({
406-
\ 'all': {'leftcol': 0, 'topline': 1, 'width': 0, 'height': 0, 'skipcol': 0},
407-
\ '1000': {'leftcol': 0, 'topline': -1, 'width': 0, 'height': 0, 'skipcol': 0}
406+
\ 'all': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
407+
\ '1000': {'leftcol': 0, 'topline': -1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}
408408
\ }, event)
409409

410410
" Scroll up/down in Insert mode.
@@ -414,8 +414,8 @@ func Test_WinScrolled()
414414

415415
let event = readfile('XscrollEvent')[0]->json_decode()
416416
call assert_equal({
417-
\ 'all': {'leftcol': 0, 'topline': 1, 'width': 0, 'height': 0, 'skipcol': 0},
418-
\ '1000': {'leftcol': 0, 'topline': -1, 'width': 0, 'height': 0, 'skipcol': 0}
417+
\ 'all': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
418+
\ '1000': {'leftcol': 0, 'topline': -1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}
419419
\ }, event)
420420

421421
" Scroll the window horizontally to focus the last letter of the third line
@@ -427,8 +427,8 @@ func Test_WinScrolled()
427427

428428
let event = readfile('XscrollEvent')[0]->json_decode()
429429
call assert_equal({
430-
\ 'all': {'leftcol': 5, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0},
431-
\ '1000': {'leftcol': -5, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0}
430+
\ 'all': {'leftcol': 5, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
431+
\ '1000': {'leftcol': -5, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}
432432
\ }, event)
433433

434434
" Ensure the command was triggered for the specified window ID.
@@ -582,6 +582,66 @@ func Test_WinScrolled_long_wrapped()
582582
call StopVimInTerminal(buf)
583583
endfunc
584584

585+
func Test_WinScrolled_diff()
586+
CheckRunVimInTerminal
587+
588+
let lines =<< trim END
589+
set diffopt+=foldcolumn:0
590+
call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
591+
vnew
592+
call setline(1, ['d', 'e', 'f', 'g', 'h', 'i'])
593+
windo diffthis
594+
func WriteScrollEvent()
595+
call writefile([json_encode(v:event)], 'XscrollEvent')
596+
endfunc
597+
au WinScrolled * call WriteScrollEvent()
598+
END
599+
call writefile(lines, 'Xtest_winscrolled_diff', 'D')
600+
let buf = RunVimInTerminal('-S Xtest_winscrolled_diff', {'rows': 8})
601+
602+
call term_sendkeys(buf, "\<C-E>")
603+
call WaitForAssert({-> assert_match('^d', term_getline(buf, 3))}, 1000)
604+
605+
let event = readfile('XscrollEvent')[0]->json_decode()
606+
call assert_equal({
607+
\ 'all': {'leftcol': 0, 'topline': 1, 'topfill': 1, 'width': 0, 'height': 0, 'skipcol': 0},
608+
\ '1000': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
609+
\ '1001': {'leftcol': 0, 'topline': 0, 'topfill': -1, 'width': 0, 'height': 0, 'skipcol': 0}
610+
\ }, event)
611+
612+
call term_sendkeys(buf, "2\<C-E>")
613+
call WaitForAssert({-> assert_match('^f', term_getline(buf, 3))}, 1000)
614+
615+
let event = readfile('XscrollEvent')[0]->json_decode()
616+
call assert_equal({
617+
\ 'all': {'leftcol': 0, 'topline': 2, 'topfill': 2, 'width': 0, 'height': 0, 'skipcol': 0},
618+
\ '1000': {'leftcol': 0, 'topline': 2, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
619+
\ '1001': {'leftcol': 0, 'topline': 0, 'topfill': -2, 'width': 0, 'height': 0, 'skipcol': 0}
620+
\ }, event)
621+
622+
call term_sendkeys(buf, "\<C-E>")
623+
call WaitForAssert({-> assert_match('^g', term_getline(buf, 3))}, 1000)
624+
625+
let event = readfile('XscrollEvent')[0]->json_decode()
626+
call assert_equal({
627+
\ 'all': {'leftcol': 0, 'topline': 2, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
628+
\ '1000': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
629+
\ '1001': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}
630+
\ }, event)
631+
632+
call term_sendkeys(buf, "2\<C-Y>")
633+
call WaitForAssert({-> assert_match('^e', term_getline(buf, 3))}, 1000)
634+
635+
let event = readfile('XscrollEvent')[0]->json_decode()
636+
call assert_equal({
637+
\ 'all': {'leftcol': 0, 'topline': 3, 'topfill': 1, 'width': 0, 'height': 0, 'skipcol': 0},
638+
\ '1000': {'leftcol': 0, 'topline': -2, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
639+
\ '1001': {'leftcol': 0, 'topline': -1, 'topfill': 1, 'width': 0, 'height': 0, 'skipcol': 0}
640+
\ }, event)
641+
642+
call StopVimInTerminal(buf)
643+
endfunc
644+
585645
func Test_WinClosed()
586646
" Test that the pattern is matched against the closed window's ID, and both
587647
" <amatch> and <afile> are set to it.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1025,
698700
/**/
699701
1024,
700702
/**/

src/window.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,6 +2855,9 @@ snapshot_windows_scroll_size(void)
28552855
FOR_ALL_WINDOWS(wp)
28562856
{
28572857
wp->w_last_topline = wp->w_topline;
2858+
#ifdef FEAT_DIFF
2859+
wp->w_last_topfill = wp->w_topfill;
2860+
#endif
28582861
wp->w_last_leftcol = wp->w_leftcol;
28592862
wp->w_last_skipcol = wp->w_skipcol;
28602863
wp->w_last_width = wp->w_width;
@@ -2886,6 +2889,9 @@ make_win_info_dict(
28862889
int width,
28872890
int height,
28882891
int topline,
2892+
# ifdef FEAT_DIFF
2893+
int topfill,
2894+
# endif
28892895
int leftcol,
28902896
int skipcol)
28912897
{
@@ -2910,6 +2916,13 @@ make_win_info_dict(
29102916
tv.vval.v_number = topline;
29112917
if (dict_add_tv(d, "topline", &tv) == FAIL)
29122918
break;
2919+
#ifdef FEAT_DIFF
2920+
tv.vval.v_number = topfill;
2921+
#else
2922+
tv.vval.v_number = 0;
2923+
#endif
2924+
if (dict_add_tv(d, "topfill", &tv) == FAIL)
2925+
break;
29132926
tv.vval.v_number = leftcol;
29142927
if (dict_add_tv(d, "leftcol", &tv) == FAIL)
29152928
break;
@@ -2958,6 +2971,9 @@ check_window_scroll_resize(
29582971
int tot_width = 0;
29592972
int tot_height = 0;
29602973
int tot_topline = 0;
2974+
# ifdef FEAT_DIFF
2975+
int tot_topfill = 0;
2976+
# endif
29612977
int tot_leftcol = 0;
29622978
int tot_skipcol = 0;
29632979
#endif
@@ -2995,6 +3011,9 @@ check_window_scroll_resize(
29953011
}
29963012

29973013
int scroll_changed = wp->w_last_topline != wp->w_topline
3014+
#ifdef FEAT_DIFF
3015+
|| wp->w_last_topfill != wp->w_topfill
3016+
#endif
29983017
|| wp->w_last_leftcol != wp->w_leftcol
29993018
|| wp->w_last_skipcol != wp->w_skipcol;
30003019
if (scroll_changed)
@@ -3011,10 +3030,16 @@ check_window_scroll_resize(
30113030
int width = wp->w_width - wp->w_last_width;
30123031
int height = wp->w_height - wp->w_last_height;
30133032
int topline = wp->w_topline - wp->w_last_topline;
3033+
#ifdef FEAT_DIFF
3034+
int topfill = wp->w_topfill - wp->w_last_topfill;
3035+
#endif
30143036
int leftcol = wp->w_leftcol - wp->w_last_leftcol;
30153037
int skipcol = wp->w_skipcol - wp->w_last_skipcol;
3016-
dict_T *d = make_win_info_dict(width, height,
3017-
topline, leftcol, skipcol);
3038+
dict_T *d = make_win_info_dict(width, height, topline,
3039+
#ifdef FEAT_DIFF
3040+
topfill,
3041+
#endif
3042+
leftcol, skipcol);
30183043
if (d == NULL)
30193044
break;
30203045
char winid[NUMBUFLEN];
@@ -3029,6 +3054,9 @@ check_window_scroll_resize(
30293054
tot_width += abs(width);
30303055
tot_height += abs(height);
30313056
tot_topline += abs(topline);
3057+
#ifdef FEAT_DIFF
3058+
tot_topfill += abs(topfill);
3059+
#endif
30323060
tot_leftcol += abs(leftcol);
30333061
tot_skipcol += abs(skipcol);
30343062
}
@@ -3038,8 +3066,11 @@ check_window_scroll_resize(
30383066
#ifdef FEAT_EVAL
30393067
if (v_event != NULL)
30403068
{
3041-
dict_T *alldict = make_win_info_dict(tot_width, tot_height,
3042-
tot_topline, tot_leftcol, tot_skipcol);
3069+
dict_T *alldict = make_win_info_dict(tot_width, tot_height, tot_topline,
3070+
# ifdef FEAT_DIFF
3071+
tot_topfill,
3072+
# endif
3073+
tot_leftcol, tot_skipcol);
30433074
if (alldict != NULL)
30443075
{
30453076
if (dict_add_dict(v_event, "all", alldict) == FAIL)

0 commit comments

Comments
 (0)