- commit
- c2d9e74
- parent
- c37e04e
- author
- Eric Bower
- date
- 2024-12-23 21:48:39 -0500 EST
chore: sort range diff
3 files changed,
+30,
-10
+9,
-0
1@@ -3,6 +3,7 @@ package git
2 import (
3 "fmt"
4 "math"
5+ "sort"
6
7 ha "github.com/oddg/hungarian-algorithm"
8 "github.com/sergi/go-diff/diffmatchpatch"
9@@ -32,6 +33,7 @@ func NewPatchRange(patch *Patch) *PatchRange {
10
11 type RangeDiffOutput struct {
12 Header string
13+ Order int
14 Diff []diffmatchpatch.Diff
15 Type string
16 }
17@@ -45,6 +47,7 @@ func output(a []*PatchRange, b []*PatchRange) []*RangeDiffOutput {
18 &RangeDiffOutput{
19 Header: outputPairHeader(patchA, nil, i+1, -1),
20 Type: "rm",
21+ Order: i + 1,
22 },
23 )
24 }
25@@ -57,6 +60,7 @@ func output(a []*PatchRange, b []*PatchRange) []*RangeDiffOutput {
26 &RangeDiffOutput{
27 Header: outputPairHeader(nil, patchB, -1, j+1),
28 Type: "add",
29+ Order: j + 1,
30 },
31 )
32 continue
33@@ -68,6 +72,7 @@ func output(a []*PatchRange, b []*PatchRange) []*RangeDiffOutput {
34 &RangeDiffOutput{
35 Header: outputPairHeader(patchA, patchB, patchB.Matching+1, patchA.Matching+1),
36 Type: "equal",
37+ Order: patchA.Matching + 1,
38 },
39 )
40 } else {
41@@ -80,6 +85,7 @@ func output(a []*PatchRange, b []*PatchRange) []*RangeDiffOutput {
42 outputs = append(
43 outputs,
44 &RangeDiffOutput{
45+ Order: patchA.Matching + 1,
46 Header: header,
47 Diff: diff,
48 Type: "diff",
49@@ -87,6 +93,9 @@ func output(a []*PatchRange, b []*PatchRange) []*RangeDiffOutput {
50 )
51 }
52 }
53+ sort.Slice(outputs, func(i, j int) bool {
54+ return outputs[i].Order < outputs[j].Order
55+ })
56 return outputs
57 }
58
+8,
-0
1@@ -78,6 +78,14 @@ details {
2 font-weight: normal !important;
3 }
4
5+.interdiff summary {
6+ margin: 0 !important;
7+}
8+
9+.interdiff pre {
10+ overflow-x: scroll;
11+}
12+
13 @media only screen and (max-width: 40em) {
14 .collapse {
15 flex-direction: column;
+13,
-10
1@@ -70,17 +70,20 @@
2 </code>
3 </div>
4 {{- if .Diff -}}
5- <pre>
6- {{- range .Diff -}}
7- {{- if eq .Type -1 -}}
8- <span style="color: tomato;">{{.Text}}</span>
9- {{- else if eq .Type 1 -}}
10- <span style="color: limegreen;">{{.Text}}</span>
11- {{- else -}}
12- <span>{{.Text}}</span>
13+ <details class="interdiff">
14+ <summary class="text-sm">Summary</summary>
15+ <div><pre>
16+ {{- range .Diff -}}
17+ {{- if eq .Type -1 -}}
18+ <span style="color: tomato;">{{.Text}}</span>
19+ {{- else if eq .Type 1 -}}
20+ <span style="color: limegreen;">{{.Text}}</span>
21+ {{- else -}}
22+ <span>{{.Text}}</span>
23+ {{- end -}}
24 {{- end -}}
25- {{- end -}}
26- </pre>
27+ </pre></div>
28+ </details>
29 {{- end -}}
30 {{- end -}}
31 </div>