Skip to content

Commit bb714b4

Browse files
committed
fine tune
1 parent 78cd2ce commit bb714b4

File tree

3 files changed

+4
-18
lines changed

3 files changed

+4
-18
lines changed

services/gitdiff/gitdiff.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (d *DiffLine) RenderBlobExcerptButtons(fileNameHash string, data *DiffBlobE
191191
link += fmt.Sprintf("&pull_issue_index=%d", data.PullIssueIndex)
192192
}
193193
return htmlutil.HTMLFormat(
194-
`<button class="code-expander-button" hx-target="closest tr" hx-get="%s" data-hidden-comment-ids="%s">%s</button>`,
194+
`<button class="code-expander-button" hx-target="closest tr" hx-get="%s" data-hidden-comment-ids=",%s,">%s</button>`,
195195
link, dataHiddenCommentIDs, svg.RenderHTML(svgName),
196196
)
197197
}
@@ -224,7 +224,7 @@ func FillHiddenCommentIDsForDiffLine(line *DiffLine, lineComments map[int64][]*i
224224
var hiddenCommentIDs []int64
225225
for commentLineNum, comments := range lineComments {
226226
if commentLineNum < 0 {
227-
continue // Skip left-side
227+
continue // Skip left-side, unchanged lines always use "right (proposed)" side for comments
228228
}
229229
lineNum := int(commentLineNum)
230230
isEndOfFileExpansion := line.SectionInfo.RightHunkSize == 0

services/gitdiff/gitdiff_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ func TestDiffLine_RenderBlobExcerptButtons(t *testing.T) {
935935
"octicon-fold-up",
936936
"direction=down",
937937
"direction=up",
938-
"data-hidden-comment-ids=\"200,201\"",
938+
`data-hidden-comment-ids=",200,201,"`, // use leading and trailing commas to ensure exact match by CSS selector `attr*=",id,"`
939939
"pull_issue_index=42",
940940
"2 hidden comment(s)",
941941
},

web_src/js/features/repo-diff.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ async function onLocationHashChange() {
246246
const issueCommentPrefix = '#issuecomment-';
247247
if (currentHash.startsWith(issueCommentPrefix)) {
248248
const commentId = currentHash.substring(issueCommentPrefix.length);
249-
const expandButton = findExpandButtonForComment(commentId);
249+
const expandButton = document.querySelector<HTMLElement>(`.code-expander-button[data-hidden-comment-ids*=",${commentId},"]`);
250250
if (expandButton) {
251251
// avoid infinite loop, do not re-click the button if already clicked
252252
const attrAutoLoadClicked = 'data-auto-load-clicked';
@@ -270,20 +270,6 @@ async function onLocationHashChange() {
270270
}
271271
}
272272

273-
// Find the expand button that contains the target comment ID
274-
function findExpandButtonForComment(commentId: string): HTMLElement | null {
275-
const expandButtons = document.querySelectorAll('.code-expander-button[data-hidden-comment-ids]');
276-
for (const button of expandButtons) {
277-
const hiddenIdsAttr = button.getAttribute('data-hidden-comment-ids');
278-
if (!hiddenIdsAttr) continue;
279-
const hiddenIds = hiddenIdsAttr.split(',').filter(Boolean);
280-
if (hiddenIds.includes(commentId)) {
281-
return button as HTMLElement;
282-
}
283-
}
284-
return null;
285-
}
286-
287273
function initRepoDiffHashChangeListener() {
288274
window.addEventListener('hashchange', onLocationHashChange);
289275
onLocationHashChange();

0 commit comments

Comments
 (0)