From 05d9e6a9e850ee797a4a018e72156dd62831a4b6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 30 Oct 2024 09:05:11 +0800 Subject: vim-patch:9.1.0822: topline might be changed in diff mode unexpectedly (#30988) Problem: topline might be changed in diff mode unexpectedly (Jaehwang Jung) Solution: do not re-calculate topline, when using line() func in diff mode. fixes: vim/vim#15812 closes: vim/vim#15950 https://github.com/vim/vim/commit/05a40e07c2f0e41b708c4c75a6aa7d0e7f6201a3 Co-authored-by: Christian Brabandt --- test/functional/ui/diff_spec.lua | 106 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) (limited to 'test/functional/ui/diff_spec.lua') diff --git a/test/functional/ui/diff_spec.lua b/test/functional/ui/diff_spec.lua index d6a04f90f6..8b965e8a97 100644 --- a/test/functional/ui/diff_spec.lua +++ b/test/functional/ui/diff_spec.lua @@ -2054,3 +2054,109 @@ it('diff mode overlapped diff blocks will be merged', function() | ]]) end) + +-- oldtest: Test_diff_topline_noscroll() +it('diff mode does not scroll with line("w0")', function() + local screen = Screen.new(45, 20) + screen:attach() + exec([[ + set scrolloff=5 + call setline(1, range(1,60)) + vnew + call setline(1, range(1,10) + range(50,60)) + windo diffthis + norm! G + exe "norm! 30\" + ]]) + screen:expect([[ + {7: }9 │{7: }9 | + {7: }10 │{7: }10 | + {7: }{23:--------------------}│{7: }{22:11 }| + {7: }{23:--------------------}│{7: }{22:12 }| + {7: }{23:--------------------}│{7: }{22:13 }| + {7: }{23:--------------------}│{7: }{22:14 }| + {7: }{23:--------------------}│{7: }{22:15 }| + {7: }{23:--------------------}│{7: }{22:16 }| + {7: }{23:--------------------}│{7: }{22:17 }| + {7: }{23:--------------------}│{7: }{22:18 }| + {7: }{23:--------------------}│{7: }{22:19 }| + {7: }{23:--------------------}│{7: }{22:20 }| + {7: }{23:--------------------}│{7: }{22:^21 }| + {7: }{23:--------------------}│{7: }{22:22 }| + {7: }{23:--------------------}│{7: }{22:23 }| + {7: }{23:--------------------}│{7: }{22:24 }| + {7: }{23:--------------------}│{7: }{22:25 }| + {7: }{23:--------------------}│{7: }{22:26 }| + {2:[No Name] [+] }{3:[No Name] [+] }| + | + ]]) + command([[echo line('w0', 1001)]]) + screen:expect([[ + {7: }9 │{7: }9 | + {7: }10 │{7: }10 | + {7: }{23:--------------------}│{7: }{22:11 }| + {7: }{23:--------------------}│{7: }{22:12 }| + {7: }{23:--------------------}│{7: }{22:13 }| + {7: }{23:--------------------}│{7: }{22:14 }| + {7: }{23:--------------------}│{7: }{22:15 }| + {7: }{23:--------------------}│{7: }{22:16 }| + {7: }{23:--------------------}│{7: }{22:17 }| + {7: }{23:--------------------}│{7: }{22:18 }| + {7: }{23:--------------------}│{7: }{22:19 }| + {7: }{23:--------------------}│{7: }{22:20 }| + {7: }{23:--------------------}│{7: }{22:^21 }| + {7: }{23:--------------------}│{7: }{22:22 }| + {7: }{23:--------------------}│{7: }{22:23 }| + {7: }{23:--------------------}│{7: }{22:24 }| + {7: }{23:--------------------}│{7: }{22:25 }| + {7: }{23:--------------------}│{7: }{22:26 }| + {2:[No Name] [+] }{3:[No Name] [+] }| + 9 | + ]]) + feed('p') + screen:expect([[ + {7: }{23:--------------------}│{7: }{22:39 }| + {7: }{23:--------------------}│{7: }{22:40 }| + {7: }{23:--------------------}│{7: }{22:41 }| + {7: }{23:--------------------}│{7: }{22:42 }| + {7: }{23:--------------------}│{7: }{22:43 }| + {7: }{23:--------------------}│{7: }{22:44 }| + {7: }{23:--------------------}│{7: }{22:45 }| + {7: }{23:--------------------}│{7: }{22:46 }| + {7: }{23:--------------------}│{7: }{22:47 }| + {7: }{23:--------------------}│{7: }{22:48 }| + {7: }{23:--------------------}│{7: }{22:49 }| + {7: }^50 │{7: }50 | + {7: }51 │{7: }51 | + {7: }52 │{7: }52 | + {7: }53 │{7: }53 | + {7: }54 │{7: }54 | + {7: }55 │{7: }55 | + {7:+ }{13:+-- 5 lines: 56····}│{7:+ }{13:+-- 5 lines: 56····}| + {3:[No Name] [+] }{2:[No Name] [+] }| + 9 | + ]]) + feed('p') + screen:expect([[ + {7: }{23:--------------------}│{7: }{22:39 }| + {7: }{23:--------------------}│{7: }{22:40 }| + {7: }{23:--------------------}│{7: }{22:41 }| + {7: }{23:--------------------}│{7: }{22:42 }| + {7: }{23:--------------------}│{7: }{22:43 }| + {7: }{23:--------------------}│{7: }{22:^44 }| + {7: }{23:--------------------}│{7: }{22:45 }| + {7: }{23:--------------------}│{7: }{22:46 }| + {7: }{23:--------------------}│{7: }{22:47 }| + {7: }{23:--------------------}│{7: }{22:48 }| + {7: }{23:--------------------}│{7: }{22:49 }| + {7: }50 │{7: }50 | + {7: }51 │{7: }51 | + {7: }52 │{7: }52 | + {7: }53 │{7: }53 | + {7: }54 │{7: }54 | + {7: }55 │{7: }55 | + {7:+ }{13:+-- 5 lines: 56····}│{7:+ }{13:+-- 5 lines: 56····}| + {2:[No Name] [+] }{3:[No Name] [+] }| + 9 | + ]]) +end) -- cgit From e61228a214ebda9845db9462dad0a8c362d3963f Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 11 Nov 2024 22:15:19 +0100 Subject: fix(tests): needing two calls to setup a screen is cringe Before calling "attach" a screen object is just a dummy container for (row, col) values whose purpose is to be sent as part of the "attach" function call anyway. Just create the screen in an attached state directly. Keep the complete (row, col, options) config together. It is still completely valid to later detach and re-attach as needed, including to another session. --- test/functional/ui/diff_spec.lua | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'test/functional/ui/diff_spec.lua') diff --git a/test/functional/ui/diff_spec.lua b/test/functional/ui/diff_spec.lua index 8b965e8a97..95159011f1 100644 --- a/test/functional/ui/diff_spec.lua +++ b/test/functional/ui/diff_spec.lua @@ -53,7 +53,6 @@ describe('Diff mode screen', function() feed('w:diffthisw') screen = Screen.new(40, 16) - screen:attach() end) it('Add a line in beginning of file 2', function() @@ -1172,7 +1171,6 @@ end) it('win_update redraws lines properly', function() local screen screen = Screen.new(50, 10) - screen:attach() screen:set_default_attr_ids({ [1] = { bold = true, foreground = Screen.colors.Blue1 }, [2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, @@ -1250,7 +1248,6 @@ end) -- oldtest: Test_diff_rnu() it('diff updates line numbers below filler lines', function() local screen = Screen.new(40, 14) - screen:attach() exec([[ call setline(1, ['a', 'a', 'a', 'y', 'b', 'b', 'b', 'b', 'b']) vnew @@ -1310,7 +1307,6 @@ end) -- oldtest: Test_diff_with_scroll_and_change() it('Align the filler lines when changing text in diff mode', function() local screen = Screen.new(40, 20) - screen:attach() exec([[ call setline(1, range(1, 15)) vnew @@ -1376,7 +1372,6 @@ end) it("diff mode doesn't restore invalid 'foldcolumn' value #21647", function() local screen = Screen.new(60, 6) - screen:attach() eq('0', api.nvim_get_option_value('foldcolumn', {})) command('diffsplit | bd') screen:expect([[ @@ -1389,7 +1384,6 @@ end) it("'relativenumber' doesn't draw beyond end of window in diff mode #29403", function() local screen = Screen.new(60, 12) - screen:attach() command('set relativenumber') feed('10aagg') command('vnew') @@ -1433,7 +1427,6 @@ it('diff mode works properly if file contains NUL bytes vim-patch:8.2.3925', fun screen:add_extra_attr_ids { [100] = { foreground = Screen.colors.Blue, bold = true, background = Screen.colors.Red }, } - screen:attach() exec([[ call setline(1, ['a', 'b', "c\n", 'd', 'e', 'f', 'g']) vnew @@ -1510,7 +1503,6 @@ end) -- oldtest: Test_diff_breakindent_after_filler() it("diff mode draws 'breakindent' correctly after filler lines", function() local screen = Screen.new(45, 8) - screen:attach() exec([[ set laststatus=0 diffopt+=followwrap breakindent breakindentopt=min:0 call setline(1, ['a', ' ' .. repeat('c', 50)]) @@ -1562,7 +1554,6 @@ it('diff mode overlapped diff blocks will be merged', function() ]]) local screen = Screen.new(35, 20) - screen:attach() command('set winwidth=10 diffopt=filler,internal') command('args Xdifile1 Xdifile2 | vert all | windo diffthis') @@ -2058,7 +2049,6 @@ end) -- oldtest: Test_diff_topline_noscroll() it('diff mode does not scroll with line("w0")', function() local screen = Screen.new(45, 20) - screen:attach() exec([[ set scrolloff=5 call setline(1, range(1,60)) -- cgit