Skip to content

Commit ffc8ce7

Browse files
zeripathsilverwindtechknowlogick
authored
Fix scrolling to resolved comment anchors (#13343)
* Fix scrolling to resolved comment anchors As described on discord, when the window.location.hash refers to a resolved comment then the scroll to functionality does not work. This PR fixes this. Signed-off-by: Andrew Thornton <[email protected]> * Apply suggestions from code review Co-authored-by: silverwind <[email protected]> Co-authored-by: silverwind <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 6c32367 commit ffc8ce7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

web_src/js/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,22 @@ async function initRepository() {
11721172
}
11731173

11741174
function initPullRequestReview() {
1175+
if (window.location.hash && window.location.hash.startsWith('#issuecomment-')) {
1176+
const commentDiv = $(window.location.hash);
1177+
if (commentDiv) {
1178+
// get the name of the parent id
1179+
const groupID = commentDiv.closest('div[id^="code-comments-"]').attr('id');
1180+
if (groupID && groupID.startsWith('code-comments-')) {
1181+
const id = groupID.substr(14);
1182+
$(`#show-outdated-${id}`).addClass('hide');
1183+
$(`#code-comments-${id}`).removeClass('hide');
1184+
$(`#code-preview-${id}`).removeClass('hide');
1185+
$(`#hide-outdated-${id}`).removeClass('hide');
1186+
$(window).scrollTop(commentDiv.offset().top);
1187+
}
1188+
}
1189+
}
1190+
11751191
$('.show-outdated').on('click', function (e) {
11761192
e.preventDefault();
11771193
const id = $(this).data('comment');

0 commit comments

Comments
 (0)