diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-10-30 09:05:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-30 09:05:11 +0800 |
commit | 05d9e6a9e850ee797a4a018e72156dd62831a4b6 (patch) | |
tree | 913916e0f463e62040ff3b87936f6a5843e79b42 | |
parent | ff93cccbc1ce4bb217d503e2ac5f81f9023d4d43 (diff) | |
download | rneovim-05d9e6a9e850ee797a4a018e72156dd62831a4b6.tar.gz rneovim-05d9e6a9e850ee797a4a018e72156dd62831a4b6.tar.bz2 rneovim-05d9e6a9e850ee797a4a018e72156dd62831a4b6.zip |
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 <cb@256bit.org>
-rw-r--r-- | src/nvim/eval/funcs.c | 8 | ||||
-rw-r--r-- | test/functional/ui/diff_spec.lua | 106 | ||||
-rw-r--r-- | test/old/testdir/test_diffmode.vim | 27 |
3 files changed, 141 insertions, 0 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index e8b9288717..8f676d7906 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -4351,9 +4351,17 @@ static void f_line(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (wp != NULL && tp != NULL) { switchwin_T switchwin; if (switch_win_noblock(&switchwin, wp, tp, true) == OK) { + // in diff mode, prevent that the window scrolls + // and keep the topline + if (curwin->w_p_diff && switchwin.sw_curwin->w_p_diff) { + skip_update_topline = true; + } check_cursor(curwin); fp = var2fpos(&argvars[0], true, &fnum, false); } + if (curwin->w_p_diff && switchwin.sw_curwin->w_p_diff) { + skip_update_topline = false; + } restore_win_noblock(&switchwin, true); } } else { 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\<C-y>" + ]]) + 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('<C-W>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('<C-W>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) diff --git a/test/old/testdir/test_diffmode.vim b/test/old/testdir/test_diffmode.vim index a448ed9b7f..a97006a7cc 100644 --- a/test/old/testdir/test_diffmode.vim +++ b/test/old/testdir/test_diffmode.vim @@ -2007,4 +2007,31 @@ func Test_diff_overlapped_diff_blocks_will_be_merged() call StopVimInTerminal(buf) endfunc +" switching windows in diff mode caused an unneccessary scroll +func Test_diff_topline_noscroll() + CheckScreendump + + let content =<< trim END + call setline(1, range(1,60)) + vnew + call setline(1, range(1,10) + range(50,60)) + windo diffthis + norm! G + exe "norm! 30\<C-y>" + END + call writefile(content, 'Xcontent', 'D') + let buf = RunVimInTerminal('-S Xcontent', {'rows': 20}) + call VerifyScreenDump(buf, 'Test_diff_topline_1', {}) + call term_sendkeys(buf, ":echo line('w0', 1001)\<cr>") + call term_wait(buf) + call VerifyScreenDump(buf, 'Test_diff_topline_2', {}) + call term_sendkeys(buf, "\<C-W>p") + call term_wait(buf) + call VerifyScreenDump(buf, 'Test_diff_topline_3', {}) + call term_sendkeys(buf, "\<C-W>p") + call term_wait(buf) + call VerifyScreenDump(buf, 'Test_diff_topline_4', {}) + call StopVimInTerminal(buf) +endfunc + " vim: shiftwidth=2 sts=2 expandtab |