mirror of
https://github.com/neovim/neovim.git
synced 2026-03-28 19:32:01 +00:00
feat(diff): merge adjacent blocks using inline:word (#37085)
vim-patch:9.2.0174: diff: inline word-diffs can be fragmented
Problem: When using 'diffopt=inline:word', lines were excessively
fragmented with punctuation creating separate highlight
blocks, making it harder to read the diffs.
Solution: Added 'diff_refine_inline_word_highlight()' to merge
adjacent diff blocks that are separated by small gaps of
non-word characters (up to 5 bytes by default) (HarshK97).
When using inline:word diff mode, adjacent changed words separated by
punctuation or whitespace are now merged into a single highlight block
if the gap between them contains fewer than 5 non-word characters.
This creates more readable diffs and closely matches GitHub's own diff
display.
closes: vim/vim#19098
42c6686c78
This commit is contained in:
@@ -2316,7 +2316,7 @@ it('diff mode inline highlighting', function()
|
||||
|
||||
command('set diffopt=internal,filler diffopt+=inline:word')
|
||||
screen:expect([[
|
||||
{7: }{27:^abcdef}{4: }{27:ghi}{4: }{27:jk}{4: n }│{7: }{27:aBcef}{4: }{27:gHi}{4: }{27:lm}{4: n }|
|
||||
{7: }{27:^abcdef ghi jk}{4: n }│{7: }{27:aBcef gHi lm}{4: n }|
|
||||
{7: }{22:x }│{7: }{23:----------------}|
|
||||
{7: }y │{7: }y |
|
||||
{7: }{23:----------------}│{7: }{22:z }|
|
||||
@@ -2497,7 +2497,7 @@ it('diff mode inline highlighting', function()
|
||||
)
|
||||
command('set diffopt=internal,filler diffopt+=inline:word')
|
||||
screen:expect([[
|
||||
{7: }{4:^🚀}{27:⛵️}{4:一二}{27:三}{4:ひら}{100:が}{4:な}{27:Δέλτα}{4: }{27:Δelta}{4: fooba}│{7: }{4:🚀}{27:🛸}{4:一二}{27:四}{4:ひらな}{27:δέλτα}{4: }{27:δelta}{4: foobar }|
|
||||
{7: }{4:^🚀}{27:⛵️}{4:一二}{27:三}{4:ひら}{27:がなΔέλτα Δelta}{4: fooba}│{7: }{4:🚀}{27:🛸}{4:一二}{27:四}{4:ひら}{27:なδέλτα δelta}{4: foobar }|
|
||||
{1:~ }│{1:~ }|*17
|
||||
{3:Xdifile1 }{2:Xdifile2 }|
|
||||
|
|
||||
@@ -2573,9 +2573,9 @@ it('diff mode inline highlighting', function()
|
||||
]])
|
||||
command('set diffopt=internal,filler diffopt+=inline:word,iwhite')
|
||||
screen:expect([[
|
||||
{7: }{4:^this is }│{7: }{4:this is }{27:some}{4: }{27:test}{4: }|
|
||||
{7: }{27:sometest}{4: }{27:text}{4: }{27:foo}{4: }│{7: }{27:texts}{4: }|
|
||||
{7: }{27:baz}{4: }{27:abc}{4: }{27:def}{4: }│{7: }{27:foo}{4: }{27:bar}{4: }{27:abX}{4: }{27:Yef}{4: }|
|
||||
{7: }{4:^this is }│{7: }{4:this is }{27:some test}{4: }|
|
||||
{7: }{27:sometest text foo}{4: }│{7: }{27:texts}{4: }|
|
||||
{7: }{27:baz abc def}{4: }│{7: }{27:foo bar abX}{4: }{27:Yef}{4: }|
|
||||
{7: }{27:one}{4: }│{7: }{27:oneword}{4: another word }|
|
||||
{7: }{27:word}{4: another word }│{7: }{23:----------------------}|
|
||||
{7: }{22:additional line }│{7: }{23:----------------------}|
|
||||
@@ -2597,9 +2597,9 @@ it('diff mode inline highlighting', function()
|
||||
]])
|
||||
command('set diffopt=internal,filler diffopt+=inline:word,iwhiteeol')
|
||||
screen:expect([[
|
||||
{7: }{4:^this }{100: }{4:is }│{7: }{4:this is }{27:some}{4: }{27:test}{4: }|
|
||||
{7: }{27:sometest}{4: }{27:text}{4: foo }│{7: }{27:texts}{4: }|
|
||||
{7: }{27:baz}{4: }{27:abc}{4: }{27:def}{4: }│{7: }{4:foo }{27:bar}{4: }{27:abX}{4: }{27:Yef}{4: }|
|
||||
{7: }{4:^this }{100: }{4:is }│{7: }{4:this is }{27:some test}{4: }|
|
||||
{7: }{27:sometest text}{4: foo }│{7: }{27:texts}{4: }|
|
||||
{7: }{27:baz abc def}{4: }│{7: }{4:foo }{27:bar abX Yef}{4: }|
|
||||
{7: }{27:one}{4: }│{7: }{27:oneword}{4: another word }|
|
||||
{7: }{27:word}{4: another word }│{7: }{23:----------------------}|
|
||||
{7: }{22:additional line }│{7: }{23:----------------------}|
|
||||
@@ -2765,7 +2765,7 @@ it('diff mode inline highlighting with 3 buffers', function()
|
||||
command('set iskeyword+=+ | 2wincmd w | set iskeyword+=- | 1wincmd w')
|
||||
command('set diffopt=internal,filler diffopt+=inline:word')
|
||||
local s4 = [[
|
||||
{7: }{27:^This+is}{4:=}{27:a}{4:-setence }│{7: }{27:This+is}{4:=}{27:another}{4:-setenc}│{7: }{27:That+is}{4:=}{27:a}{4:-setence }|
|
||||
{7: }{27:^This+is=a}{4:-setence }│{7: }{27:This+is=another}{4:-setenc}│{7: }{27:That+is=a}{4:-setence }|
|
||||
{1:~ }│{1:~ }│{1:~ }|*17
|
||||
{3:Xdifile1 }{2:Xdifile2 Xdifile3 }|
|
||||
|
|
||||
|
||||
Reference in New Issue
Block a user