diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 7753979db7..5aa7e33325 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -95,10 +95,10 @@ static bool diff_need_update = false; // ex_diffupdate needs to be called #define ALL_WHITE_DIFF (DIFF_IWHITE | DIFF_IWHITEALL | DIFF_IWHITEEOL) #define ALL_INLINE (DIFF_INLINE_NONE | DIFF_INLINE_SIMPLE | DIFF_INLINE_CHAR | DIFF_INLINE_WORD) #define ALL_INLINE_DIFF (DIFF_INLINE_CHAR | DIFF_INLINE_WORD) -static int diff_flags = DIFF_INTERNAL | DIFF_FILLER | DIFF_CLOSE_OFF; +static int diff_flags = DIFF_INTERNAL | DIFF_FILLER | DIFF_CLOSE_OFF | DIFF_LINEMATCH; static int diff_algorithm = 0; -static int linematch_lines = 0; +static int linematch_lines = 40; #define LBUFLEN 50 // length of line in diff file diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 2b9eeff190..96a28d337c 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -834,6 +834,42 @@ describe('startup', function() ]]) end) + it("default 'diffopt' is applied with -d", function() + clear({ + args = { + '-d', + 'test/functional/fixtures/diff/startup_old.txt', + 'test/functional/fixtures/diff/startup_new.txt', + '--cmd', + 'set laststatus=0', + }, + }) + local screen = Screen.new(80, 24) + screen:expect([[ + {7:+ }{13:^+-- 15 lines: package main············}│{7:+ }{13:+-- 15 lines: package main···········}| + {7: } │{7: } | + {7: }func printCharacters(str string) strin│{7: }func printCharacters(str string) stri| + {7: } return str │{7: } return str | + {7: }} │{7: }} | + {7: } │{7: } | + {7: }func main() { │{7: }func main() { | + {7: }{23:--------------------------------------}│{7: }{22: hello := "Hello, World!" }| + {7: }{23:--------------------------------------}│{7: }{22: }| + {7: }{4: fmt.Print}{27:Ln}{4:(compressString("aa}│{7: }{4: fmt.Print(compressString("aaa}| + {7: }{4: fmt.Print}{27:Ln}{4:(compressString("go}│{7: }{4: fmt.Print(compressString("gol}| + {7: }{4: fmt.Print}{27:Ln}{4:(removeDuplicate("a}│{7: }{4: fmt.Print(removeDuplicate("aa}| + {7: }{4: fmt.Print}{27:Ln}{4:(reverseAndDouble("}│{7: }{4: fmt.Print(reverseAndDouble("a}| + {7: }{4: fmt.Print}{27:Ln}{4:(printCharacters("g}│{7: }{4: fmt.Print(printCharacters("go}| + {7: }{23:--------------------------------------}│{7: }{22: }| + {7: }{23:--------------------------------------}│{7: }{22: fmt.Println(hello) }| + {7: }} │{7: }} | + {1:~ }│{1:~ }|*6 + | + ]]) + command('let &diffopt = &diffopt') + screen:expect_unchanged() + end) + it('does not crash if --embed is given twice', function() clear { args = { '--embed' } } assert_alive() diff --git a/test/functional/fixtures/diff/startup_new.txt b/test/functional/fixtures/diff/startup_new.txt new file mode 100644 index 0000000000..4a6dc729ef --- /dev/null +++ b/test/functional/fixtures/diff/startup_new.txt @@ -0,0 +1,31 @@ +package main + +import "fmt" + +func compressString(str string) string { + return str +} + +func removeDuplicate(str string) string { + return str +} + +func reverseAndDouble(str string) string { + return str +} + +func printCharacters(str string) string { + return str +} + +func main() { + hello := "Hello, World!" + + fmt.Print(compressString("aaaabbccgh")) + fmt.Print(compressString("golang")) + fmt.Print(removeDuplicate("aabccchbbccaaa")) + fmt.Print(reverseAndDouble("abcdfgh")) + fmt.Print(printCharacters("golang")) + + fmt.Println(hello) +} diff --git a/test/functional/fixtures/diff/startup_old.txt b/test/functional/fixtures/diff/startup_old.txt new file mode 100644 index 0000000000..3964e61b34 --- /dev/null +++ b/test/functional/fixtures/diff/startup_old.txt @@ -0,0 +1,27 @@ +package main + +import "fmt" + +func compressString(str string) string { + return str +} + +func removeDuplicate(str string) string { + return str +} + +func reverseAndDouble(str string) string { + return str +} + +func printCharacters(str string) string { + return str +} + +func main() { + fmt.PrintLn(compressString("aaaabbccgh")) + fmt.PrintLn(compressString("golang")) + fmt.PrintLn(removeDuplicate("aabccchbbccaaa")) + fmt.PrintLn(reverseAndDouble("abcdfgh")) + fmt.PrintLn(printCharacters("golang")) +} diff --git a/test/functional/ui/diff_spec.lua b/test/functional/ui/diff_spec.lua index a50b3d07d1..1eed0672db 100644 --- a/test/functional/ui/diff_spec.lua +++ b/test/functional/ui/diff_spec.lua @@ -1249,6 +1249,7 @@ end) it('diff updates line numbers below filler lines', function() local screen = Screen.new(40, 14) exec([[ + set diffopt=internal,filler,closeoff call setline(1, ['a', 'a', 'a', 'y', 'b', 'b', 'b', 'b', 'b']) vnew call setline(1, ['a', 'a', 'a', 'x', 'x', 'x', 'b', 'b', 'b', 'b', 'b']) @@ -1384,6 +1385,7 @@ end) it("'relativenumber' doesn't draw beyond end of window in diff mode #29403", function() local screen = Screen.new(60, 12) + command('set diffopt=internal,filler,closeoff') command('set relativenumber') feed('10aagg') command('vnew')