neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 0b8a9bde0eee1414ae0b67bbc2a972c5b961b83f
parent 810a234978d3013e736c6efce0dd5875759cfc56
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Sun, 24 Aug 2025 14:42:10 +0800

fix(diff): set default diff flags properly (#35450)


Diffstat:
Msrc/nvim/diff.c | 4++--
Mtest/functional/core/startup_spec.lua | 36++++++++++++++++++++++++++++++++++++
Atest/functional/fixtures/diff/startup_new.txt | 31+++++++++++++++++++++++++++++++
Atest/functional/fixtures/diff/startup_old.txt | 27+++++++++++++++++++++++++++
Mtest/functional/ui/diff_spec.lua | 2++
5 files changed, 98 insertions(+), 2 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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('10aa<CR><Esc>gg') command('vnew')