diff options
-rw-r--r-- | src/nvim/diff.c | 3 | ||||
-rw-r--r-- | test/functional/ui/linematch_spec.lua | 28 | ||||
-rw-r--r-- | test/old/testdir/test_diffmode.vim | 47 |
3 files changed, 68 insertions, 10 deletions
diff --git a/src/nvim/diff.c b/src/nvim/diff.c index ee063a330e..68441f7adc 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -2127,7 +2127,8 @@ int diff_check_with_linestatus(win_T *wp, linenr_T lnum, int *linestatus) // Useful for scrollbind calculations which need to count all the filler lines // above the screen. if (lnum >= wp->w_topline && lnum < wp->w_botline - && !dp->is_linematched && diff_linematch(dp)) { + && !dp->is_linematched && diff_linematch(dp) + && diff_check_sanity(curtab, dp)) { run_linematch_algorithm(dp); } diff --git a/test/functional/ui/linematch_spec.lua b/test/functional/ui/linematch_spec.lua index b564c01eaa..3593604c49 100644 --- a/test/functional/ui/linematch_spec.lua +++ b/test/functional/ui/linematch_spec.lua @@ -1147,4 +1147,32 @@ describe('regressions', function() }, } end) + + -- oldtest: Test_linematch_3diffs_sanity_check() + it('sanity check with 3 diff buffers', function() + clear() + screen = Screen.new(75, 20) + n.api.nvim_buf_set_lines(0, 0, -1, false, { 'abcd', 'def', 'hij' }) + n.exec('rightbelow vnew') + n.api.nvim_buf_set_lines(0, 0, -1, false, { 'defq', 'hijk', 'nopq' }) + n.exec('rightbelow vnew') + n.api.nvim_buf_set_lines(0, 0, -1, false, { 'hijklm', 'nopqr', 'stuv' }) + n.exec([[ + set diffopt+=linematch:60 + windo diffthis | wincmd t + call feedkeys("Aq\<esc>") + call feedkeys("GAklm\<esc>") + call feedkeys("o") + ]]) + screen:expect([[ + {7: }{22:abcdq }│{7: }{23:----------------------}│{7: }{23:-----------------------}| + {7: }{4:def }│{7: }{4:def}{27:q}{4: }│{7: }{23:-----------------------}| + {7: }{4:hijk}{27:lm}{4: }│{7: }{4:hijk }│{7: }{4:hijk}{27:lm}{4: }| + {7: }{23:----------------------}│{7: }{4:nopq }│{7: }{4:nopq}{27:r}{4: }| + {7: }{4:^ }│{7: }{23:----------------------}│{7: }{27:stuv}{4: }| + {1:~ }│{1:~ }│{1:~ }|*13 + {3:[No Name] [+] }{2:[No Name] [+] [No Name] [+] }| + {5:-- INSERT --} | + ]]) + end) end) diff --git a/test/old/testdir/test_diffmode.vim b/test/old/testdir/test_diffmode.vim index b452be5061..ab64658bd0 100644 --- a/test/old/testdir/test_diffmode.vim +++ b/test/old/testdir/test_diffmode.vim @@ -1247,7 +1247,7 @@ func CloseoffSetup() call setline(1, ['one', 'tow', 'three']) diffthis call assert_equal(1, &diff) - only! + bw! endfunc func Test_diff_closeoff() @@ -2278,7 +2278,8 @@ func Test_diffget_diffput_linematch() call term_sendkeys(buf, "17gg") call term_sendkeys(buf, ":diffput\<CR>") call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_19', {}) - + " clean up + call StopVimInTerminal(buf) endfunc func Test_linematch_diff() @@ -2298,7 +2299,8 @@ func Test_linematch_diff() \ 'abc d!', \ 'd!']) call VerifyScreenDump(buf, 'Test_linematch_diff1', {}) - + " clean up + call StopVimInTerminal(buf) endfunc func Test_linematch_diff_iwhite() @@ -2324,7 +2326,8 @@ func Test_linematch_diff_iwhite() call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite1', {}) call term_sendkeys(buf, ":set diffopt+=iwhiteall\<CR>") call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite2', {}) - + " clean up + call StopVimInTerminal(buf) endfunc func Test_linematch_diff_grouping() @@ -2361,7 +2364,8 @@ func Test_linematch_diff_grouping() \ '?C', \ '?C']) call VerifyScreenDump(buf, 'Test_linematch_diff_grouping2', {}) - + " clean up + call StopVimInTerminal(buf) endfunc func Test_linematch_diff_scroll() @@ -2392,11 +2396,10 @@ func Test_linematch_diff_scroll() call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll1', {}) call term_sendkeys(buf, "3\<c-e>") call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll2', {}) - + " clean up + call StopVimInTerminal(buf) endfunc - - func Test_linematch_line_limit_exceeded() CheckScreendump call delete('.Xdifile1.swp') @@ -2443,7 +2446,8 @@ func Test_linematch_line_limit_exceeded() " alignment algorithm will run on the largest diff block here call term_sendkeys(buf, ":set diffopt+=linematch:30\<CR>") call VerifyScreenDump(buf, 'Test_linematch_line_limit_exceeded2', {}) - + " clean up + call StopVimInTerminal(buf) endfunc func Test_linematch_3diffs() @@ -2480,6 +2484,31 @@ func Test_linematch_3diffs() \ " BBB", \ " BBB"]) call VerifyScreenDump(buf, 'Test_linematch_3diffs1', {}) + " clean up + call StopVimInTerminal(buf) +endfunc +" this used to access invalid memory +func Test_linematch_3diffs_sanity_check() + CheckScreendump + call delete('.Xfile_linematch1.swp') + call delete('.Xfile_linematch2.swp') + call delete('.Xfile_linematch3.swp') + let lines =<< trim END + set diffopt+=linematch:60 + call feedkeys("Aq\<esc>") + call feedkeys("GAklm\<esc>") + call feedkeys("o") + END + call writefile(lines, 'Xlinematch_3diffs.vim', 'D') + call writefile(['abcd', 'def', 'hij'], 'Xfile_linematch1', 'D') + call writefile(['defq', 'hijk', 'nopq'], 'Xfile_linematch2', 'D') + call writefile(['hijklm', 'nopqr', 'stuv'], 'Xfile_linematch3', 'D') + call WriteDiffFiles3(0, [], [], []) + let buf = RunVimInTerminal('-d -S Xlinematch_3diffs.vim Xfile_linematch1 Xfile_linematch2 Xfile_linematch3', {}) + call VerifyScreenDump(buf, 'Test_linematch_3diffs2', {}) + + " clean up + call StopVimInTerminal(buf) endfunc " vim: shiftwidth=2 sts=2 expandtab |