Skip to content

Commit 30e3fd1

Browse files
committed
fix(diff): update hidden comment count on code expand buttons
1 parent 8216008 commit 30e3fd1

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

routers/web/repo/compare.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,28 @@ func ExcerptBlob(ctx *context.Context) {
982982
return line.Comments[i].CreatedUnix < line.Comments[j].CreatedUnix
983983
})
984984
}
985+
986+
// Recalculate hidden comment counts for expand buttons after loading comments
987+
for _, line := range section.Lines {
988+
if line.Type == gitdiff.DiffLineSection && line.SectionInfo != nil {
989+
hiddenCommentCount := 0
990+
// Check if there are comments in the hidden range
991+
for commentLineNum := range lineComments {
992+
absLineNum := commentLineNum
993+
if absLineNum < 0 {
994+
absLineNum = -absLineNum
995+
}
996+
// Count comments that are in the hidden range
997+
if int(absLineNum) > line.SectionInfo.LastRightIdx && int(absLineNum) < line.SectionInfo.RightIdx {
998+
hiddenCommentCount++
999+
}
1000+
}
1001+
if hiddenCommentCount > 0 {
1002+
line.HasHiddenComments = true
1003+
line.HiddenCommentCount = hiddenCommentCount
1004+
}
1005+
}
1006+
}
9851007
}
9861008
}
9871009
}

templates/repo/diff/blob_excerpt.tmpl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}">
88
<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
99
{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
10-
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptLink}}&{{$line.GetBlobExcerptQuery}}&style=split&direction=down">
10+
<button class="code-expander-button{{if $line.HasHiddenComments}} has-hidden-comments{{end}}" hx-target="closest tr" hx-get="{{$blobExcerptLink}}&{{$line.GetBlobExcerptQuery}}&style=split&direction=down" title="{{if $line.HasHiddenComments}}{{$line.HiddenCommentCount}} hidden comment(s){{end}}">
1111
{{svg "octicon-fold-down"}}
12+
{{if $line.HasHiddenComments}}<span class="ui mini label">{{$line.HiddenCommentCount}}</span>{{end}}
1213
</button>
1314
{{end}}
1415
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
15-
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptLink}}&{{$line.GetBlobExcerptQuery}}&style=split&direction=up">
16+
<button class="code-expander-button{{if $line.HasHiddenComments}} has-hidden-comments{{end}}" hx-target="closest tr" hx-get="{{$blobExcerptLink}}&{{$line.GetBlobExcerptQuery}}&style=split&direction=up" title="{{if $line.HasHiddenComments}}{{$line.HiddenCommentCount}} hidden comment(s){{end}}">
1617
{{svg "octicon-fold-up"}}
18+
{{if $line.HasHiddenComments}}<span class="ui mini label">{{$line.HiddenCommentCount}}</span>{{end}}
1719
</button>
1820
{{end}}
1921
{{if eq $expandDirection 2}}
20-
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptLink}}&{{$line.GetBlobExcerptQuery}}&style=split">
22+
<button class="code-expander-button{{if $line.HasHiddenComments}} has-hidden-comments{{end}}" hx-target="closest tr" hx-get="{{$blobExcerptLink}}&{{$line.GetBlobExcerptQuery}}&style=split" title="{{if $line.HasHiddenComments}}{{$line.HiddenCommentCount}} hidden comment(s){{end}}">
2123
{{svg "octicon-fold"}}
24+
{{if $line.HasHiddenComments}}<span class="ui mini label">{{$line.HiddenCommentCount}}</span>{{end}}
2225
</button>
2326
{{end}}
2427
</div>
@@ -84,18 +87,21 @@
8487
<td colspan="2" class="lines-num">
8588
<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
8689
{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
87-
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptLink}}&{{$line.GetBlobExcerptQuery}}&style=unified&direction=down">
90+
<button class="code-expander-button{{if $line.HasHiddenComments}} has-hidden-comments{{end}}" hx-target="closest tr" hx-get="{{$blobExcerptLink}}&{{$line.GetBlobExcerptQuery}}&style=unified&direction=down" title="{{if $line.HasHiddenComments}}{{$line.HiddenCommentCount}} hidden comment(s){{end}}">
8891
{{svg "octicon-fold-down"}}
92+
{{if $line.HasHiddenComments}}<span class="ui mini label">{{$line.HiddenCommentCount}}</span>{{end}}
8993
</button>
9094
{{end}}
9195
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
92-
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptLink}}&{{$line.GetBlobExcerptQuery}}&style=unified&direction=up">
96+
<button class="code-expander-button{{if $line.HasHiddenComments}} has-hidden-comments{{end}}" hx-target="closest tr" hx-get="{{$blobExcerptLink}}&{{$line.GetBlobExcerptQuery}}&style=unified&direction=up" title="{{if $line.HasHiddenComments}}{{$line.HiddenCommentCount}} hidden comment(s){{end}}">
9397
{{svg "octicon-fold-up"}}
98+
{{if $line.HasHiddenComments}}<span class="ui mini label">{{$line.HiddenCommentCount}}</span>{{end}}
9499
</button>
95100
{{end}}
96101
{{if eq $expandDirection 2}}
97-
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptLink}}&{{$line.GetBlobExcerptQuery}}&style=unified">
102+
<button class="code-expander-button{{if $line.HasHiddenComments}} has-hidden-comments{{end}}" hx-target="closest tr" hx-get="{{$blobExcerptLink}}&{{$line.GetBlobExcerptQuery}}&style=unified" title="{{if $line.HasHiddenComments}}{{$line.HiddenCommentCount}} hidden comment(s){{end}}">
98103
{{svg "octicon-fold"}}
104+
{{if $line.HasHiddenComments}}<span class="ui mini label">{{$line.HiddenCommentCount}}</span>{{end}}
99105
</button>
100106
{{end}}
101107
</div>

0 commit comments

Comments
 (0)