on main help sign in
fix(diffview): respect line style even if it's the last one with ellipsis
9f5d70cAndrey Nering
internal/exp/diffview/diffview.go+29−7
@@ -331,12 +331,13 @@ outer:
331 isLastHunk := i+1 == len(dv.unified.Hunks)
331 isLastHunk := i+1 == len(dv.unified.Hunks)
332 isLastLine := j+1 == len(h.Lines)
332 isLastLine := j+1 == len(h.Lines)
333 if hasReachedHeight && (!isLastHunk || !isLastLine) {
333 if hasReachedHeight && (!isLastHunk || !isLastLine) {
334+ lineStyle := dv.lineStyleForType(l.Kind)
334 if dv.lineNumbers {
335 if dv.lineNumbers {
335− write(dv.style.EqualLine.LineNumber.Render(pad("…", dv.beforeNumDigits)))
336+ write(lineStyle.LineNumber.Render(pad("…", dv.beforeNumDigits)))
336− write(dv.style.EqualLine.LineNumber.Render(pad("…", dv.afterNumDigits)))
337+ write(lineStyle.LineNumber.Render(pad("…", dv.afterNumDigits)))
337 }
338 }
338 write(fullContentStyle.Render(
339 write(fullContentStyle.Render(
339− dv.style.EqualLine.Code.Width(dv.fullCodeWidth).Render(" …"),
340+ lineStyle.Code.Width(dv.fullCodeWidth).Render(" …"),
340 ))
341 ))
341 write("\n")
342 write("\n")
342 break outer
343 break outer
@@ -436,17 +437,25 @@ outer:
436 isLastHunk := i+1 == len(dv.unified.Hunks)
437 isLastHunk := i+1 == len(dv.unified.Hunks)
437 isLastLine := j+1 == len(h.lines)
438 isLastLine := j+1 == len(h.lines)
438 if hasReachedHeight && (!isLastHunk || !isLastLine) {
439 if hasReachedHeight && (!isLastHunk || !isLastLine) {
440+ lineStyle := dv.style.MissingLine
441+ if l.before != nil {
442+ lineStyle = dv.lineStyleForType(l.before.Kind)
443+ }
439 if dv.lineNumbers {
444 if dv.lineNumbers {
440− write(dv.style.EqualLine.LineNumber.Render(pad("…", dv.beforeNumDigits)))
445+ write(lineStyle.LineNumber.Render(pad("…", dv.beforeNumDigits)))
441 }
446 }
442 write(beforeFullContentStyle.Render(
447 write(beforeFullContentStyle.Render(
443− dv.style.EqualLine.Code.Width(dv.fullCodeWidth).Render(" …"),
448+ lineStyle.Code.Width(dv.fullCodeWidth).Render(" …"),
444 ))
449 ))
450+ lineStyle = dv.style.MissingLine
451+ if l.after != nil {
452+ lineStyle = dv.lineStyleForType(l.after.Kind)
453+ }
445 if dv.lineNumbers {
454 if dv.lineNumbers {
446− write(dv.style.EqualLine.LineNumber.Render(pad("…", dv.afterNumDigits)))
455+ write(lineStyle.LineNumber.Render(pad("…", dv.afterNumDigits)))
447 }
456 }
448 write(afterFullContentStyle.Render(
457 write(afterFullContentStyle.Render(
449− dv.style.EqualLine.Code.Width(dv.fullCodeWidth).Render(" …"),
458+ lineStyle.Code.Width(dv.fullCodeWidth).Render(" …"),
450 ))
459 ))
451 write("\n")
460 write("\n")
452 break outer
461 break outer
@@ -573,3 +582,16 @@ func (dv *DiffView) hunkShownLines(h *udiff.Hunk) (before, after int) {
573 }
582 }
574 return
583 return
575}
584}
585+
586+func (dv *DiffView) lineStyleForType(t udiff.OpKind) LineStyle {
587+ switch t {
588+ case udiff.Equal:
589+ return dv.style.EqualLine
590+ case udiff.Insert:
591+ return dv.style.InsertLine
592+ case udiff.Delete:
593+ return dv.style.DeleteLine
594+ default:
595+ return dv.style.MissingLine
596+ }
597+}
internal/exp/diffview/testdata/TestDiffViewHeight/Split/DarkMode/HeightOf005.golden+1−1
@@ -2,4 +2,4 @@
2  2     2   
2  2     2   
3  3  import (   3  import ( 
3  3  import (   3  import ( 
4  4  "fmt"   4  "fmt" 
4  4  "fmt"   4  "fmt" 
5−  …  …   …  … 
5+  …  …   …  … 
internal/exp/diffview/testdata/TestDiffViewHeight/Split/DarkMode/HeightOf013.golden+1−1
@@ -10,4 +10,4 @@
10  9  }  10  } 
10  9  }  10  } 
11 10    11   
11 10    11   
12 11  func getContent() string {  12  func getContent() string { 
12 11  func getContent() string {  12  func getContent() string { 
13−  …  …   …  … 
13+  …  …   …  … 
internal/exp/diffview/testdata/TestDiffViewHeight/Split/DarkMode/HeightOf014.golden+1−1
@@ -11,4 +11,4 @@
11 10    11   
11 10    11   
12 11  func getContent() string {  12  func getContent() string { 
12 11  func getContent() string {  12  func getContent() string { 
13 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
13 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
14−  …  …   …  … 
14+  …  …   …  … 
internal/exp/diffview/testdata/TestDiffViewHeight/Split/LightMode/HeightOf005.golden+1−1
@@ -2,4 +2,4 @@
2  2     2   
2  2     2   
3  3  import (   3  import ( 
3  3  import (   3  import ( 
4  4  "fmt"   4  "fmt" 
4  4  "fmt"   4  "fmt" 
5−  …  …   …  … 
5+  …  …   …  … 
internal/exp/diffview/testdata/TestDiffViewHeight/Split/LightMode/HeightOf013.golden+1−1
@@ -10,4 +10,4 @@
10  9  }  10  } 
10  9  }  10  } 
11 10    11   
11 10    11   
12 11  func getContent() string {  12  func getContent() string { 
12 11  func getContent() string {  12  func getContent() string { 
13−  …  …   …  … 
13+  …  …   …  … 
internal/exp/diffview/testdata/TestDiffViewHeight/Split/LightMode/HeightOf014.golden+1−1
@@ -11,4 +11,4 @@
11 10    11   
11 10    11   
12 11  func getContent() string {  12  func getContent() string { 
12 11  func getContent() string {  12  func getContent() string { 
13 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
13 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
14−  …  …   …  … 
14+  …  …   …  … 
internal/exp/diffview/testdata/TestDiffViewHeight/Unified/DarkMode/HeightOf005.golden+1−1
@@ -2,4 +2,4 @@
2  2   2   
2  2   2   
3  3   3  import ( 
3  3   3  import ( 
4  4   4  "fmt" 
4  4   4  "fmt" 
5−  …   …  … 
5+  …   …  … 
internal/exp/diffview/testdata/TestDiffViewHeight/Unified/DarkMode/HeightOf013.golden+1−1
@@ -10,4 +10,4 @@
10  9  10  } 
10  9  10  } 
11 10  11   
11 10  11   
12 11  12  func getContent() string { 
12 11  12  func getContent() string { 
13−  …   …  … 
13+  …   …  … 
internal/exp/diffview/testdata/TestDiffViewHeight/Unified/DarkMode/HeightOf014.golden+1−1
@@ -11,4 +11,4 @@
11 10  11   
11 10  11   
12 11  12  func getContent() string { 
12 11  12  func getContent() string { 
13 12    -  return "Hello, world!" 
13 12    -  return "Hello, world!" 
14−  …   …  … 
14+  …   …  … 
internal/exp/diffview/testdata/TestDiffViewHeight/Unified/DarkMode/HeightOf015.golden+1−1
@@ -12,4 +12,4 @@
12 11  12  func getContent() string { 
12 11  12  func getContent() string { 
13 12    -  return "Hello, world!" 
13 12    -  return "Hello, world!" 
14    13 +  content := strings.ToUpper("Hello, World!") 
14    13 +  content := strings.ToUpper("Hello, World!") 
15−  …   …  … 
15+  …   …  … 
internal/exp/diffview/testdata/TestDiffViewHeight/Unified/LightMode/HeightOf005.golden+1−1
@@ -2,4 +2,4 @@
2  2   2   
2  2   2   
3  3   3  import ( 
3  3   3  import ( 
4  4   4  "fmt" 
4  4   4  "fmt" 
5−  …   …  … 
5+  …   …  … 
internal/exp/diffview/testdata/TestDiffViewHeight/Unified/LightMode/HeightOf013.golden+1−1
@@ -10,4 +10,4 @@
10  9  10  } 
10  9  10  } 
11 10  11   
11 10  11   
12 11  12  func getContent() string { 
12 11  12  func getContent() string { 
13−  …   …  … 
13+  …   …  … 
internal/exp/diffview/testdata/TestDiffViewHeight/Unified/LightMode/HeightOf014.golden+1−1
@@ -11,4 +11,4 @@
11 10  11   
11 10  11   
12 11  12  func getContent() string { 
12 11  12  func getContent() string { 
13 12    -  return "Hello, world!" 
13 12    -  return "Hello, world!" 
14−  …   …  … 
14+  …   …  … 
internal/exp/diffview/testdata/TestDiffViewHeight/Unified/LightMode/HeightOf015.golden+1−1
@@ -12,4 +12,4 @@
12 11  12  func getContent() string { 
12 11  12  func getContent() string { 
13 12    -  return "Hello, world!" 
13 12    -  return "Hello, world!" 
14    13 +  content := strings.ToUpper("Hello, World!") 
14    13 +  content := strings.ToUpper("Hello, World!") 
15−  …   …  … 
15+  …   …  … 
internal/exp/diffview/testdata/TestDiffViewYOffset/Split/YOffsetOf00.golden+1−1
@@ -2,4 +2,4 @@
2  2     2   
2  2     2   
3  3  import (   3  import ( 
3  3  import (   3  import ( 
4  4  "fmt"   4  "fmt" 
4  4  "fmt"   4  "fmt" 
5−  …  …   …  … 
5+  …  …   …  … 
internal/exp/diffview/testdata/TestDiffViewYOffset/Split/YOffsetOf08.golden+1−1
@@ -2,4 +2,4 @@
2  9  }  10  } 
2  9  }  10  } 
3 10    11   
3 10    11   
4 11  func getContent() string {  12  func getContent() string { 
4 11  func getContent() string {  12  func getContent() string { 
5−  …  …   …  … 
5+  …  …   …  … 
internal/exp/diffview/testdata/TestDiffViewYOffset/Split/YOffsetOf09.golden+1−1
@@ -2,4 +2,4 @@
2 10    11   
2 10    11   
3 11  func getContent() string {  12  func getContent() string { 
3 11  func getContent() string {  12  func getContent() string { 
4 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
4 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
5−  …  …   …  … 
5+  …  …   …  … 
internal/exp/diffview/testdata/TestDiffViewYOffset/Unified/YOffsetOf00.golden+1−1
@@ -2,4 +2,4 @@
2  2   2   
2  2   2   
3  3   3  import ( 
3  3   3  import ( 
4  4   4  "fmt" 
4  4   4  "fmt" 
5−  …   …  … 
5+  …   …  … 
internal/exp/diffview/testdata/TestDiffViewYOffset/Unified/YOffsetOf08.golden+1−1
@@ -2,4 +2,4 @@
2  9  10  } 
2  9  10  } 
3 10  11   
3 10  11   
4 11  12  func getContent() string { 
4 11  12  func getContent() string { 
5−  …   …  … 
5+  …   …  … 
internal/exp/diffview/testdata/TestDiffViewYOffset/Unified/YOffsetOf09.golden+1−1
@@ -2,4 +2,4 @@
2 10  11   
2 10  11   
3 11  12  func getContent() string { 
3 11  12  func getContent() string { 
4 12    -  return "Hello, world!" 
4 12    -  return "Hello, world!" 
5−  …   …  … 
5+  …   …  … 
internal/exp/diffview/testdata/TestDiffViewYOffset/Unified/YOffsetOf10.golden+1−1
@@ -2,4 +2,4 @@
2 11  12  func getContent() string { 
2 11  12  func getContent() string { 
3 12    -  return "Hello, world!" 
3 12    -  return "Hello, world!" 
4    13 +  content := strings.ToUpper("Hello, World!") 
4    13 +  content := strings.ToUpper("Hello, World!") 
5−  …   …  … 
5+  …   …  …