From 035d41ac5e5fcbb49eb64b72a924c4d6f89f0579 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 20 Nov 2022 08:38:46 +0800 Subject: vim-patch:partial:9.0.0913: only change in current window triggers the WinScrolled event Problem: Only a change in the current window triggers the WinScrolled event. Solution: Trigger WinScrolled if any window scrolled or changed size. (issue vim/vim#11576) https://github.com/vim/vim/commit/0a60f79fd0c328b47b36279a95282e9f8d9e7512 Skip locking of window layout and E1312. Copy the latest version of all WinScrolled tests from Vim. Note: patch 9.0.0915 is needed for the Lua tests to pass. Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_autocmd.vim | 70 ++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 8 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 70da0a9ba2..bfb4a23f42 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -311,7 +311,7 @@ func Test_WinScrolled() au WinScrolled * let g:amatch = str2nr(expand('')) au WinScrolled * let g:afile = str2nr(expand('')) END - call writefile(lines, 'Xtest_winscrolled') + call writefile(lines, 'Xtest_winscrolled', 'D') let buf = RunVimInTerminal('-S Xtest_winscrolled', {'rows': 6}) call term_sendkeys(buf, ":echo g:scrolled\") @@ -346,7 +346,36 @@ func Test_WinScrolled() call WaitForAssert({-> assert_match('^v:true ', term_getline(buf, 6))}, 1000) call StopVimInTerminal(buf) - call delete('Xtest_winscrolled') +endfunc + +func Test_WinScrolled_mouse() + CheckRunVimInTerminal + + let lines =<< trim END + set nowrap scrolloff=0 + set mouse=a term=xterm ttymouse=sgr mousetime=200 clipboard= + call setline(1, ['foo']->repeat(32)) + split + let g:scrolled = 0 + au WinScrolled * let g:scrolled += 1 + END + call writefile(lines, 'Xtest_winscrolled_mouse', 'D') + let buf = RunVimInTerminal('-S Xtest_winscrolled_mouse', {'rows': 10}) + + " With the upper split focused, send a scroll-down event to the unfocused one. + call test_setmouse(7, 1) + call term_sendkeys(buf, "\") + call TermWait(buf) + call term_sendkeys(buf, ":echo g:scrolled\") + call WaitForAssert({-> assert_match('^1', term_getline(buf, 10))}, 1000) + + " Again, but this time while we're in insert mode. + call term_sendkeys(buf, "i\\") + call TermWait(buf) + call term_sendkeys(buf, ":echo g:scrolled\") + call WaitForAssert({-> assert_match('^2', term_getline(buf, 10))}, 1000) + + call StopVimInTerminal(buf) endfunc func Test_WinScrolled_close_curwin() @@ -359,7 +388,7 @@ func Test_WinScrolled_close_curwin() au WinScrolled * close au VimLeave * call writefile(['123456'], 'Xtestout') END - call writefile(lines, 'Xtest_winscrolled_close_curwin') + call writefile(lines, 'Xtest_winscrolled_close_curwin', 'D') let buf = RunVimInTerminal('-S Xtest_winscrolled_close_curwin', {'rows': 6}) " This was using freed memory @@ -367,12 +396,38 @@ func Test_WinScrolled_close_curwin() call TermWait(buf) call StopVimInTerminal(buf) + " check the startup script finished to the end call assert_equal(['123456'], readfile('Xtestout')) - - call delete('Xtest_winscrolled_close_curwin') call delete('Xtestout') endfunc +func Test_WinScrolled_once_only() + CheckRunVimInTerminal + + let lines =<< trim END + set cmdheight=2 + call setline(1, ['aaa', 'bbb']) + let trigger_count = 0 + func ShowInfo(id) + echo g:trigger_count g:winid winlayout() + endfunc + + vsplit + split + " use a timer to show the info after a redraw + au WinScrolled * let trigger_count += 1 | let winid = expand('') | call timer_start(100, 'ShowInfo') + wincmd j + wincmd l + END + call writefile(lines, 'Xtest_winscrolled_once', 'D') + let buf = RunVimInTerminal('-S Xtest_winscrolled_once', #{rows: 10, cols: 60, statusoff: 2}) + + call term_sendkeys(buf, "\") + call VerifyScreenDump(buf, 'Test_winscrolled_once_only_1', {}) + + call StopVimInTerminal(buf) +endfunc + func Test_WinScrolled_long_wrapped() CheckRunVimInTerminal @@ -385,7 +440,7 @@ func Test_WinScrolled_long_wrapped() call setline(1, repeat('foo', height * width)) call cursor(1, height * width) END - call writefile(lines, 'Xtest_winscrolled_long_wrapped') + call writefile(lines, 'Xtest_winscrolled_long_wrapped', 'D') let buf = RunVimInTerminal('-S Xtest_winscrolled_long_wrapped', {'rows': 6}) call term_sendkeys(buf, ":echo g:scrolled\") @@ -402,8 +457,6 @@ func Test_WinScrolled_long_wrapped() call term_sendkeys(buf, '$') call term_sendkeys(buf, ":echo g:scrolled\") call WaitForAssert({-> assert_match('^3 ', term_getline(buf, 6))}, 1000) - - call delete('Xtest_winscrolled_long_wrapped') endfunc func Test_WinClosed() @@ -2788,6 +2841,7 @@ func Test_SpellFileMissing_bwipe() call assert_fails('set spell spelllang=0', 'E937:') au! SpellFileMissing + set nospell spelllang=en bwipe endfunc -- cgit From 91c192922da0240be5a8eb4045dae6cd968957e9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 20 Nov 2022 21:11:57 +0800 Subject: vim-patch:9.0.0915: WinScrolled may trigger immediately when defined Problem: WinScrolled may trigger immediately when defined. Solution: Initialize the fields in all windows. (closes vim/vim#11582) https://github.com/vim/vim/commit/29967732761d1ffb5592db5f5aa7036f5b52abf1 Co-authored-by: Bram Moolenaar --- src/nvim/testdir/test_autocmd.vim | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index bfb4a23f42..3030ecdfa9 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -428,6 +428,32 @@ func Test_WinScrolled_once_only() call StopVimInTerminal(buf) endfunc +" Check that WinScrolled is not triggered immediately when defined and there +" are split windows. +func Test_WinScrolled_not_when_defined() + CheckRunVimInTerminal + + let lines =<< trim END + call setline(1, ['aaa', 'bbb']) + echo 'nothing happened' + func ShowTriggered(id) + echo 'triggered' + endfunc + END + call writefile(lines, 'Xtest_winscrolled_not', 'D') + let buf = RunVimInTerminal('-S Xtest_winscrolled_not', #{rows: 10, cols: 60, statusoff: 2}) + call term_sendkeys(buf, ":split\") + call TermWait(buf) + " use a timer to show the message after redrawing + call term_sendkeys(buf, ":au WinScrolled * call timer_start(100, 'ShowTriggered')\") + call VerifyScreenDump(buf, 'Test_winscrolled_not_when_defined_1', {}) + + call term_sendkeys(buf, "\") + call VerifyScreenDump(buf, 'Test_winscrolled_not_when_defined_2', {}) + + call StopVimInTerminal(buf) +endfunc + func Test_WinScrolled_long_wrapped() CheckRunVimInTerminal -- cgit