Skip to content

Commit 77a2d75

Browse files
zeripathsilverwindtechknowlogick
authored
Fix scrolling to resolved comment anchors (#13343) (#13371)
* 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: techknowlogick <[email protected]>
1 parent 79d9cda commit 77a2d75

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
@@ -1170,6 +1170,22 @@ async function initRepository() {
11701170
}
11711171

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

0 commit comments

Comments
 (0)