patch 9.1.1027: no sanitize check when running linematch

Problem:  no sanitize check when running linematch
Solution: add sanitize check before applying the linematch algorithm,
          similar to diff_find_change() (Jonathon)

closes: #16446

Signed-off-by: Jonathon <jonathonwhite@protonmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Jonathon
2025-01-17 13:37:35 +01:00
committed by Christian Brabandt
parent 3a738fccaa
commit ca307efe48
4 changed files with 62 additions and 10 deletions

View File

@ -2351,7 +2351,8 @@ diff_check_with_linestatus(win_T *wp, linenr_T lnum, int *linestatus)
// Don't run linematch when lnum is offscreen. 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);
if (dp->is_linematched)

View File

@ -0,0 +1,20 @@
| +0#0000e05#a8a8a8255@1|a+0#0000000#5fd7ff255|b|c|d|q| @17||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@21||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@21
| +0#0000e05#a8a8a8255@1|d+0#0000000#ffd7ff255|e|f| @19||+1&#ffffff0| +0#0000e05#a8a8a8255@1|d+0#0000000#ffd7ff255|e|f|q+2&#ff404010| +0&#ffd7ff255@17||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@21
| +0#0000e05#a8a8a8255@1|h+0#0000000#ffd7ff255|i|j|k|l+2&#ff404010|m| +0&#ffd7ff255@16||+1&#ffffff0| +0#0000e05#a8a8a8255@1|h+0#0000000#ffd7ff255|i|j|k| @17||+1&#ffffff0| +0#0000e05#a8a8a8255@1|h+0#0000000#ffd7ff255|i|j|k|l+2&#ff404010|m| +0&#ffd7ff255@15
| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@22||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|n+0#0000000#ffd7ff255|o|p|q| @17||+1&#ffffff0| +0#0000e05#a8a8a8255@1|n+0#0000000#ffd7ff255|o|p|q|r+2&#ff404010| +0&#ffd7ff255@16
| +0#0000e05#a8a8a8255@1> +0#0000000#ffd7ff255@22||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@21||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|s+2#0000000#ff404010|t|u|v| +0&#ffd7ff255@17
|~+0#4040ff13#ffffff0| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|<+3#0000000&|e|m|a|t|c|h|1| |[|+|]| |4|,|1| @5|A|l@1| |<+1&&|l|i|n|e|m|a|t|c|h|2| |3|,|1| @5|A|l@1| |<|l|i|n|e|m|a|t|c|h|3| |3|,|1| @5|A|l@1
|-+2&&@1| |I|N|S|E|R|T| |-@1| +0&&@62

View File

@ -1265,7 +1265,7 @@ func CloseoffSetup()
call setline(1, ['one', 'tow', 'three'])
diffthis
call assert_equal(1, &diff)
only!
bw!
endfunc
func Test_diff_closeoff()
@ -2529,7 +2529,8 @@ func Test_diffget_diffput_linematch()
" put from window 2 using dp line 17
call term_sendkeys(buf, "2\<c-w>w")
call term_sendkeys(buf, "17gg")
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)
@ -2549,7 +2550,8 @@ func Test_linematch_diff()
\ '// d?',
\ '// d?' ],
\ ['!',
\ 'abc d!',
\ 'abc d!',
\ 'd!'])
call VerifyScreenDump(buf, 'Test_linematch_diff1', {})
" clean up
call StopVimInTerminal(buf)
@ -2575,7 +2577,8 @@ func Test_linematch_diff_iwhite()
\ ' // for (int j = 0; j < 10; i++) {',
\ ' // }',
\ '}'])
call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite1', {})
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)
@ -2612,7 +2615,8 @@ func Test_linematch_diff_grouping()
\ '?C',
\ '?A',
\ '?B',
\ '?C',
\ '?C',
\ '?C'])
call VerifyScreenDump(buf, 'Test_linematch_diff_grouping2', {})
" clean up
call StopVimInTerminal(buf)
@ -2643,11 +2647,10 @@ func Test_linematch_diff_scroll()
" both windows
call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll0', {})
call term_sendkeys(buf, "3\<c-e>")
call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll1', {})
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
endfunc
call StopVimInTerminal(buf)
endfunc
@ -2694,7 +2697,8 @@ func Test_linematch_line_limit_exceeded()
\ 'something'])
call VerifyScreenDump(buf, 'Test_linematch_line_limit_exceeded1', {})
" after increasing the count to 30, the limit is not exceeded, and the
" alignment algorithm will run on the largest diff block here
" 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)
@ -2731,6 +2735,31 @@ func Test_linematch_3diffs()
\ ["",
\ " common line",
\ " BBB",
\ " 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

View File

@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1027,
/**/
1026,
/**/