Skip to content

Commit e63a041

Browse files
Move diff split code into own template file (#13919)
* Move diff split code into own template file Separate split diff view same as unified already is. Mainly because I'm working on a separate PR with this change and merge conflicts for each change to box.tmpl are annoying and I'm worried about breaking something subtle while trying to resolve them. * Fix error Co-authored-by: techknowlogick <[email protected]>
1 parent 2d71cdb commit e63a041

File tree

2 files changed

+53
-51
lines changed

2 files changed

+53
-51
lines changed

templates/repo/diff/box.tmpl

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -118,57 +118,7 @@
118118
{{template "repo/diff/image_diff" dict "file" . "root" $}}
119119
{{else}}
120120
{{if $.IsSplitStyle}}
121-
{{range $j, $section := $file.Sections}}
122-
{{range $k, $line := $section.Lines}}
123-
<tr class="{{DiffLineTypeToStr .GetType}}-code nl-{{$k}} ol-{{$k}}">
124-
{{if eq .GetType 4}}
125-
<td class="lines-num lines-num-old">
126-
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5) }}
127-
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{$.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=down" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
128-
{{svg "octicon-fold-down"}}
129-
</a>
130-
{{end}}
131-
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4) }}
132-
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{$.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=up" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
133-
{{svg "octicon-fold-up"}}
134-
</a>
135-
{{end}}
136-
{{if eq $line.GetExpandDirection 2}}
137-
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{$.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
138-
{{svg "octicon-fold"}}
139-
</a>
140-
{{end}}
141-
</td>
142-
<td colspan="5" class="lines-code lines-code-old "><code class="code-inner">{{$section.GetComputedInlineDiffFor $line}}</span></td>
143-
{{else}}
144-
<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}"></span></td>
145-
<td class="lines-type-marker lines-type-marker-old">{{if $line.LeftIdx}}<span class="mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span>{{end}}</td>
146-
<td class="lines-code lines-code-old halfwidth">{{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 2))}}<a class="ui primary button add-code-comment add-code-comment-left" data-path="{{$file.Name}}" data-side="left" data-idx="{{$line.LeftIdx}}">{{svg "octicon-plus"}}</a>{{end}}<code class="code-inner">{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></td>
147-
<td class="lines-num lines-num-new" data-line-num="{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}"><span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}"></span></td>
148-
<td class="lines-type-marker lines-type-marker-new">{{if $line.RightIdx}}<span class="mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span>{{end}}</td>
149-
<td class="lines-code lines-code-new halfwidth">{{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 3))}}<a class="ui primary button add-code-comment add-code-comment-right" data-path="{{$file.Name}}" data-side="right" data-idx="{{$line.RightIdx}}">{{svg "octicon-plus"}}</a>{{end}}<code class="code-inner">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></td>
150-
{{end}}
151-
</tr>
152-
{{if gt (len $line.Comments) 0}}
153-
<tr class="add-code-comment">
154-
<td class="lines-num"></td>
155-
<td class="lines-type-marker"></td>
156-
<td class="add-comment-left">
157-
{{if eq $line.GetCommentSide "previous"}}
158-
{{template "repo/diff/conversation" mergeinto $ "comments" $line.Comments}}
159-
{{end}}
160-
</td>
161-
<td class="lines-num"></td>
162-
<td class="lines-type-marker"></td>
163-
<td class="add-comment-right">
164-
{{if eq $line.GetCommentSide "proposed"}}
165-
{{template "repo/diff/conversation" mergeinto $ "comments" $line.Comments}}
166-
{{end}}
167-
</td>
168-
</tr>
169-
{{end}}
170-
{{end}}
171-
{{end}}
121+
{{template "repo/diff/section_split" dict "file" . "root" $}}
172122
{{else}}
173123
{{template "repo/diff/section_unified" dict "file" . "root" $}}
174124
{{end}}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{{$file := .file}}
2+
{{range $j, $section := $file.Sections}}
3+
{{range $k, $line := $section.Lines}}
4+
<tr class="{{DiffLineTypeToStr .GetType}}-code nl-{{$k}} ol-{{$k}}">
5+
{{if eq .GetType 4}}
6+
<td class="lines-num lines-num-old">
7+
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5) }}
8+
<a role="button" class="blob-excerpt" data-url="{{$.root.RepoLink}}/blob_excerpt/{{$.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=down" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
9+
{{svg "octicon-fold-down"}}
10+
</a>
11+
{{end}}
12+
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4) }}
13+
<a role="button" class="blob-excerpt" data-url="{{$.root.RepoLink}}/blob_excerpt/{{$.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=up" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
14+
{{svg "octicon-fold-up"}}
15+
</a>
16+
{{end}}
17+
{{if eq $line.GetExpandDirection 2}}
18+
<a role="button" class="blob-excerpt" data-url="{{$.root.RepoLink}}/blob_excerpt/{{$.root.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
19+
{{svg "octicon-fold"}}
20+
</a>
21+
{{end}}
22+
</td>
23+
<td colspan="5" class="lines-code lines-code-old "><code class="code-inner">{{$section.GetComputedInlineDiffFor $line}}</span></td>
24+
{{else}}
25+
<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}"></span></td>
26+
<td class="lines-type-marker lines-type-marker-old">{{if $line.LeftIdx}}<span class="mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span>{{end}}</td>
27+
<td class="lines-code lines-code-old halfwidth">{{if and $.root.SignedUserID $line.CanComment $.root.PageIsPullFiles (not (eq .GetType 2))}}<a class="ui primary button add-code-comment add-code-comment-left" data-path="{{$file.Name}}" data-side="left" data-idx="{{$line.LeftIdx}}">{{svg "octicon-plus"}}</a>{{end}}<code class="code-inner">{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></td>
28+
<td class="lines-num lines-num-new" data-line-num="{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}"><span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}"></span></td>
29+
<td class="lines-type-marker lines-type-marker-new">{{if $line.RightIdx}}<span class="mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span>{{end}}</td>
30+
<td class="lines-code lines-code-new halfwidth">{{if and $.root.SignedUserID $line.CanComment $.root.PageIsPullFiles (not (eq .GetType 3))}}<a class="ui primary button add-code-comment add-code-comment-right" data-path="{{$file.Name}}" data-side="right" data-idx="{{$line.RightIdx}}">{{svg "octicon-plus"}}</a>{{end}}<code class="code-inner">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></td>
31+
{{end}}
32+
</tr>
33+
{{if gt (len $line.Comments) 0}}
34+
<tr class="add-code-comment">
35+
<td class="lines-num"></td>
36+
<td class="lines-type-marker"></td>
37+
<td class="add-comment-left">
38+
{{if eq $line.GetCommentSide "previous"}}
39+
{{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}}
40+
{{end}}
41+
</td>
42+
<td class="lines-num"></td>
43+
<td class="lines-type-marker"></td>
44+
<td class="add-comment-right">
45+
{{if eq $line.GetCommentSide "proposed"}}
46+
{{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}}
47+
{{end}}
48+
</td>
49+
</tr>
50+
{{end}}
51+
{{end}}
52+
{{end}}

0 commit comments

Comments
 (0)