Patch 9.0.1025

7 views
Skip to first unread message

Bram Moolenaar

unread,
Dec 7, 2022, 4:19:41 AM12/7/22
to vim...@googlegroups.com

Patch 9.0.1025
Problem: WinScrolled is not triggered when filler lines change.
Solution: Add "topfill" to the values that WinScrolled triggers on.
(closes #11668)
Files: runtime/doc/windows.txt, src/structs.h, src/window.c,
src/testdir/test_autocmd.vim


*** ../vim-9.0.1024/runtime/doc/windows.txt 2022-11-22 12:40:44.062427876 +0000
--- runtime/doc/windows.txt 2022-12-07 09:08:55.805013037 +0000
***************
*** 655,663 ****
has changes, using the window ID as the key, and a total count of the changes
with the key "all". Example value for |v:event| (|Vim9| syntax):
{
! all: {width: 0, height: 2, leftcol: 0, topline: 1, skipcol: 0},
! 1003: {width: 0, height: -1, leftcol: 0, topline: 0, skipcol: 0},
! 1006: {width: 0, height: 1, leftcol: 0, topline: 1, skipcol: 0},
}

Note that the "all" entry has the absolute values of the individual windows
--- 657,665 ----
has changes, using the window ID as the key, and a total count of the changes
with the key "all". Example value for |v:event| (|Vim9| syntax):
{
! all: {width: 0, height: 2, leftcol: 0, skipcol: 0, topline: 1, topfill: 0},
! 1003: {width: 0, height: -1, leftcol: 0, skipcol: 0, topline: 0, topfill: 0},
! 1006: {width: 0, height: 1, leftcol: 0, skipcol: 0, topline: 1, topfill: 0},
}

Note that the "all" entry has the absolute values of the individual windows
*** ../vim-9.0.1024/src/structs.h 2022-11-28 18:51:38.951571546 +0000
--- src/structs.h 2022-12-07 09:08:55.805013037 +0000
***************
*** 3618,3623 ****
--- 3618,3626 ----

// five fields that are only used when there is a WinScrolled autocommand
linenr_T w_last_topline; // last known value for w_topline
+ #ifdef FEAT_DIFF
+ linenr_T w_last_topfill; // last known value for w_topfill
+ #endif
colnr_T w_last_leftcol; // last known value for w_leftcol
colnr_T w_last_skipcol; // last known value for w_skipcol
int w_last_width; // last known value for w_width
*** ../vim-9.0.1024/src/window.c 2022-11-28 20:34:47.704140309 +0000
--- src/window.c 2022-12-07 09:14:56.588704136 +0000
***************
*** 2855,2860 ****
--- 2855,2863 ----
FOR_ALL_WINDOWS(wp)
{
wp->w_last_topline = wp->w_topline;
+ #ifdef FEAT_DIFF
+ wp->w_last_topfill = wp->w_topfill;
+ #endif
wp->w_last_leftcol = wp->w_leftcol;
wp->w_last_skipcol = wp->w_skipcol;
wp->w_last_width = wp->w_width;
***************
*** 2886,2891 ****
--- 2889,2897 ----
int width,
int height,
int topline,
+ # ifdef FEAT_DIFF
+ int topfill,
+ # endif
int leftcol,
int skipcol)
{
***************
*** 2910,2915 ****
--- 2916,2928 ----
tv.vval.v_number = topline;
if (dict_add_tv(d, "topline", &tv) == FAIL)
break;
+ #ifdef FEAT_DIFF
+ tv.vval.v_number = topfill;
+ #else
+ tv.vval.v_number = 0;
+ #endif
+ if (dict_add_tv(d, "topfill", &tv) == FAIL)
+ break;
tv.vval.v_number = leftcol;
if (dict_add_tv(d, "leftcol", &tv) == FAIL)
break;
***************
*** 2958,2963 ****
--- 2971,2979 ----
int tot_width = 0;
int tot_height = 0;
int tot_topline = 0;
+ # ifdef FEAT_DIFF
+ int tot_topfill = 0;
+ # endif
int tot_leftcol = 0;
int tot_skipcol = 0;
#endif
***************
*** 2995,3000 ****
--- 3011,3019 ----
}

int scroll_changed = wp->w_last_topline != wp->w_topline
+ #ifdef FEAT_DIFF
+ || wp->w_last_topfill != wp->w_topfill
+ #endif
|| wp->w_last_leftcol != wp->w_leftcol
|| wp->w_last_skipcol != wp->w_skipcol;
if (scroll_changed)
***************
*** 3011,3020 ****
int width = wp->w_width - wp->w_last_width;
int height = wp->w_height - wp->w_last_height;
int topline = wp->w_topline - wp->w_last_topline;
int leftcol = wp->w_leftcol - wp->w_last_leftcol;
int skipcol = wp->w_skipcol - wp->w_last_skipcol;
! dict_T *d = make_win_info_dict(width, height,
! topline, leftcol, skipcol);
if (d == NULL)
break;
char winid[NUMBUFLEN];
--- 3030,3045 ----
int width = wp->w_width - wp->w_last_width;
int height = wp->w_height - wp->w_last_height;
int topline = wp->w_topline - wp->w_last_topline;
+ #ifdef FEAT_DIFF
+ int topfill = wp->w_topfill - wp->w_last_topfill;
+ #endif
int leftcol = wp->w_leftcol - wp->w_last_leftcol;
int skipcol = wp->w_skipcol - wp->w_last_skipcol;
! dict_T *d = make_win_info_dict(width, height, topline,
! #ifdef FEAT_DIFF
! topfill,
! #endif
! leftcol, skipcol);
if (d == NULL)
break;
char winid[NUMBUFLEN];
***************
*** 3029,3034 ****
--- 3054,3062 ----
tot_width += abs(width);
tot_height += abs(height);
tot_topline += abs(topline);
+ #ifdef FEAT_DIFF
+ tot_topfill += abs(topfill);
+ #endif
tot_leftcol += abs(leftcol);
tot_skipcol += abs(skipcol);
}
***************
*** 3038,3045 ****
#ifdef FEAT_EVAL
if (v_event != NULL)
{
! dict_T *alldict = make_win_info_dict(tot_width, tot_height,
! tot_topline, tot_leftcol, tot_skipcol);
if (alldict != NULL)
{
if (dict_add_dict(v_event, "all", alldict) == FAIL)
--- 3066,3076 ----
#ifdef FEAT_EVAL
if (v_event != NULL)
{
! dict_T *alldict = make_win_info_dict(tot_width, tot_height, tot_topline,
! # ifdef FEAT_DIFF
! tot_topfill,
! # endif
! tot_leftcol, tot_skipcol);
if (alldict != NULL)
{
if (dict_add_dict(v_event, "all", alldict) == FAIL)
*** ../vim-9.0.1024/src/testdir/test_autocmd.vim 2022-12-05 15:50:38.214348283 +0000
--- src/testdir/test_autocmd.vim 2022-12-07 09:08:55.805013037 +0000
***************
*** 393,400 ****

let event = readfile('XscrollEvent')[0]->json_decode()
call assert_equal({
! \ 'all': {'leftcol': 1, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0},
! \ '1000': {'leftcol': -1, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0}
\ }, event)

" Scroll up/down in Normal mode.
--- 393,400 ----

let event = readfile('XscrollEvent')[0]->json_decode()
call assert_equal({
! \ 'all': {'leftcol': 1, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
! \ '1000': {'leftcol': -1, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}
\ }, event)

" Scroll up/down in Normal mode.
***************
*** 403,410 ****

let event = readfile('XscrollEvent')[0]->json_decode()
call assert_equal({
! \ 'all': {'leftcol': 0, 'topline': 1, 'width': 0, 'height': 0, 'skipcol': 0},
! \ '1000': {'leftcol': 0, 'topline': -1, 'width': 0, 'height': 0, 'skipcol': 0}
\ }, event)

" Scroll up/down in Insert mode.
--- 403,410 ----

let event = readfile('XscrollEvent')[0]->json_decode()
call assert_equal({
! \ 'all': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
! \ '1000': {'leftcol': 0, 'topline': -1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}
\ }, event)

" Scroll up/down in Insert mode.
***************
*** 414,421 ****

let event = readfile('XscrollEvent')[0]->json_decode()
call assert_equal({
! \ 'all': {'leftcol': 0, 'topline': 1, 'width': 0, 'height': 0, 'skipcol': 0},
! \ '1000': {'leftcol': 0, 'topline': -1, 'width': 0, 'height': 0, 'skipcol': 0}
\ }, event)

" Scroll the window horizontally to focus the last letter of the third line
--- 414,421 ----

let event = readfile('XscrollEvent')[0]->json_decode()
call assert_equal({
! \ 'all': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
! \ '1000': {'leftcol': 0, 'topline': -1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}
\ }, event)

" Scroll the window horizontally to focus the last letter of the third line
***************
*** 427,434 ****

let event = readfile('XscrollEvent')[0]->json_decode()
call assert_equal({
! \ 'all': {'leftcol': 5, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0},
! \ '1000': {'leftcol': -5, 'topline': 0, 'width': 0, 'height': 0, 'skipcol': 0}
\ }, event)

" Ensure the command was triggered for the specified window ID.
--- 427,434 ----

let event = readfile('XscrollEvent')[0]->json_decode()
call assert_equal({
! \ 'all': {'leftcol': 5, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
! \ '1000': {'leftcol': -5, 'topline': 0, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}
\ }, event)

" Ensure the command was triggered for the specified window ID.
***************
*** 581,586 ****
--- 581,646 ----

call StopVimInTerminal(buf)
endfunc
+
+ func Test_WinScrolled_diff()
+ CheckRunVimInTerminal
+
+ let lines =<< trim END
+ set diffopt+=foldcolumn:0
+ call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
+ vnew
+ call setline(1, ['d', 'e', 'f', 'g', 'h', 'i'])
+ windo diffthis
+ func WriteScrollEvent()
+ call writefile([json_encode(v:event)], 'XscrollEvent')
+ endfunc
+ au WinScrolled * call WriteScrollEvent()
+ END
+ call writefile(lines, 'Xtest_winscrolled_diff', 'D')
+ let buf = RunVimInTerminal('-S Xtest_winscrolled_diff', {'rows': 8})
+
+ call term_sendkeys(buf, "\<C-E>")
+ call WaitForAssert({-> assert_match('^d', term_getline(buf, 3))}, 1000)
+
+ let event = readfile('XscrollEvent')[0]->json_decode()
+ call assert_equal({
+ \ 'all': {'leftcol': 0, 'topline': 1, 'topfill': 1, 'width': 0, 'height': 0, 'skipcol': 0},
+ \ '1000': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
+ \ '1001': {'leftcol': 0, 'topline': 0, 'topfill': -1, 'width': 0, 'height': 0, 'skipcol': 0}
+ \ }, event)
+
+ call term_sendkeys(buf, "2\<C-E>")
+ call WaitForAssert({-> assert_match('^f', term_getline(buf, 3))}, 1000)
+
+ let event = readfile('XscrollEvent')[0]->json_decode()
+ call assert_equal({
+ \ 'all': {'leftcol': 0, 'topline': 2, 'topfill': 2, 'width': 0, 'height': 0, 'skipcol': 0},
+ \ '1000': {'leftcol': 0, 'topline': 2, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
+ \ '1001': {'leftcol': 0, 'topline': 0, 'topfill': -2, 'width': 0, 'height': 0, 'skipcol': 0}
+ \ }, event)
+
+ call term_sendkeys(buf, "\<C-E>")
+ call WaitForAssert({-> assert_match('^g', term_getline(buf, 3))}, 1000)
+
+ let event = readfile('XscrollEvent')[0]->json_decode()
+ call assert_equal({
+ \ 'all': {'leftcol': 0, 'topline': 2, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
+ \ '1000': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
+ \ '1001': {'leftcol': 0, 'topline': 1, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0}
+ \ }, event)
+
+ call term_sendkeys(buf, "2\<C-Y>")
+ call WaitForAssert({-> assert_match('^e', term_getline(buf, 3))}, 1000)
+
+ let event = readfile('XscrollEvent')[0]->json_decode()
+ call assert_equal({
+ \ 'all': {'leftcol': 0, 'topline': 3, 'topfill': 1, 'width': 0, 'height': 0, 'skipcol': 0},
+ \ '1000': {'leftcol': 0, 'topline': -2, 'topfill': 0, 'width': 0, 'height': 0, 'skipcol': 0},
+ \ '1001': {'leftcol': 0, 'topline': -1, 'topfill': 1, 'width': 0, 'height': 0, 'skipcol': 0}
+ \ }, event)
+
+ call StopVimInTerminal(buf)
+ endfunc

func Test_WinClosed()
" Test that the pattern is matched against the closed window's ID, and both
*** ../vim-9.0.1024/src/version.c 2022-12-06 16:56:40.070760722 +0000
--- src/version.c 2022-12-07 09:17:10.364590926 +0000
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 1025,
/**/

--
Vi is clearly superior to emacs, since "vi" has only two characters
(and two keystrokes), while "emacs" has five. (Randy C. Ford)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages