diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-12-07 18:34:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-07 18:34:39 +0800 |
commit | f92aab5f704f6e94e80f2fcbab42acc272a66a29 (patch) | |
tree | 8f107c2a9e5c6ddc21973e0f3bf8be96ab0791b9 /src | |
parent | f8aa2a0deaf473af0e6b4640356eaf5477c6ee90 (diff) | |
download | rneovim-f92aab5f704f6e94e80f2fcbab42acc272a66a29.tar.gz rneovim-f92aab5f704f6e94e80f2fcbab42acc272a66a29.tar.bz2 rneovim-f92aab5f704f6e94e80f2fcbab42acc272a66a29.zip |
vim-patch:9.0.1025: WinScrolled is not triggered when filler lines change (#21325)
Problem: WinScrolled is not triggered when filler lines change.
Solution: Add "topfill" to the values that WinScrolled triggers on.
(closes vim/vim#11668)
https://github.com/vim/vim/commit/3fc84dc2c7efecd7c14ce341cd777475058936fd
Cherry-pick StopVimInTerminal() from patch 9.0.1010.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/buffer_defs.h | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_autocmd.vim | 78 | ||||
-rw-r--r-- | src/nvim/window.c | 20 |
3 files changed, 86 insertions, 13 deletions
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 8b01e23afd..3d3c6f0588 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -1193,6 +1193,7 @@ struct window_S { // five fields that are only used when there is a WinScrolled autocommand linenr_T w_last_topline; ///< last known value for w_topline + linenr_T w_last_topfill; ///< last known value for w_topfill 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 diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 199721b15e..704ff6ec55 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -382,8 +382,8 @@ func Test_WinScrolled() 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} + \ '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. @@ -392,8 +392,8 @@ func Test_WinScrolled() 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} + \ '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. @@ -403,8 +403,8 @@ func Test_WinScrolled() 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} + \ '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 @@ -416,8 +416,8 @@ func Test_WinScrolled() 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} + \ '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. @@ -567,6 +567,68 @@ func Test_WinScrolled_long_wrapped() call term_sendkeys(buf, '$') call term_sendkeys(buf, ":echo g:scrolled\<CR>") call WaitForAssert({-> assert_match('^3 ', term_getline(buf, 6))}, 1000) + + 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() diff --git a/src/nvim/window.c b/src/nvim/window.c index 1216bd8dcc..75320bcb7d 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -5306,6 +5306,7 @@ void snapshot_windows_scroll_size(void) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { wp->w_last_topline = wp->w_topline; + wp->w_last_topfill = wp->w_topfill; wp->w_last_leftcol = wp->w_leftcol; wp->w_last_skipcol = wp->w_skipcol; wp->w_last_width = wp->w_width; @@ -5327,7 +5328,8 @@ void may_make_initial_scroll_size_snapshot(void) /// window. /// Returns the dictionary with refcount set to one. /// Returns NULL on internal error. -static dict_T *make_win_info_dict(int width, int height, int topline, int leftcol, int skipcol) +static dict_T *make_win_info_dict(int width, int height, int topline, int topfill, int leftcol, + int skipcol) { dict_T *const d = tv_dict_alloc(); d->dv_refcount = 1; @@ -5351,6 +5353,10 @@ static dict_T *make_win_info_dict(int width, int height, int topline, int leftco if (tv_dict_add_tv(d, S_LEN("topline"), &tv) == FAIL) { break; } + tv.vval.v_number = topfill; + if (tv_dict_add_tv(d, S_LEN("topfill"), &tv) == FAIL) { + break; + } tv.vval.v_number = leftcol; if (tv_dict_add_tv(d, S_LEN("leftcol"), &tv) == FAIL) { break; @@ -5394,6 +5400,7 @@ static int check_window_scroll_resize(int *size_count, win_T **first_scroll_win, int tot_width = 0; int tot_height = 0; int tot_topline = 0; + int tot_topfill = 0; int tot_leftcol = 0; int tot_skipcol = 0; @@ -5426,6 +5433,7 @@ static int check_window_scroll_resize(int *size_count, win_T **first_scroll_win, } const bool scroll_changed = wp->w_last_topline != wp->w_topline + || wp->w_last_topfill != wp->w_topfill || wp->w_last_leftcol != wp->w_leftcol || wp->w_last_skipcol != wp->w_skipcol; if (scroll_changed) { @@ -5440,10 +5448,11 @@ static int check_window_scroll_resize(int *size_count, win_T **first_scroll_win, 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 topfill = wp->w_topfill - wp->w_last_topfill; 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); + dict_T *d = make_win_info_dict(width, height, topline, + topfill, leftcol, skipcol); if (d == NULL) { break; } @@ -5458,14 +5467,15 @@ static int check_window_scroll_resize(int *size_count, win_T **first_scroll_win, tot_width += abs(width); tot_height += abs(height); tot_topline += abs(topline); + tot_topfill += abs(topfill); tot_leftcol += abs(leftcol); tot_skipcol += abs(skipcol); } } if (v_event != NULL) { - dict_T *alldict = make_win_info_dict(tot_width, tot_height, - tot_topline, tot_leftcol, tot_skipcol); + dict_T *alldict = make_win_info_dict(tot_width, tot_height, tot_topline, + tot_topfill, tot_leftcol, tot_skipcol); if (alldict != NULL) { if (tv_dict_add_dict(v_event, S_LEN("all"), alldict) == FAIL) { tv_dict_unref(alldict); |