Skip to content

Commit a3476e5

Browse files
authored
Wrap around for previous/next buttons (#16319)
Fixes #16317 Wrap around from last to first comment when clicking "Next" on last comment. Wrap around from first to last comment when clicking "Previous" on first comment.
1 parent 290f458 commit a3476e5

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

web_src/js/index.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -947,21 +947,19 @@ async function initRepository() {
947947
const $conversation = $(e.currentTarget).closest('.comment-code-cloud');
948948
const $conversations = $('.comment-code-cloud:not(.hide)');
949949
const index = $conversations.index($conversation);
950-
if (index !== 0) {
951-
const $previousConversation = $conversations.eq(index - 1);
952-
const anchor = $previousConversation.find('.comment').first().attr('id');
953-
window.location.href = `#${anchor}`;
954-
}
950+
const previousIndex = index > 0 ? index - 1 : $conversations.length - 1;
951+
const $previousConversation = $conversations.eq(previousIndex);
952+
const anchor = $previousConversation.find('.comment').first().attr('id');
953+
window.location.href = `#${anchor}`;
955954
});
956955
$(document).on('click', '.next-conversation', (e) => {
957956
const $conversation = $(e.currentTarget).closest('.comment-code-cloud');
958957
const $conversations = $('.comment-code-cloud:not(.hide)');
959958
const index = $conversations.index($conversation);
960-
if (index !== $conversations.length - 1) {
961-
const $nextConversation = $conversations.eq(index + 1);
962-
const anchor = $nextConversation.find('.comment').first().attr('id');
963-
window.location.href = `#${anchor}`;
964-
}
959+
const nextIndex = index < $conversations.length - 1 ? index + 1 : 0;
960+
const $nextConversation = $conversations.eq(nextIndex);
961+
const anchor = $nextConversation.find('.comment').first().attr('id');
962+
window.location.href = `#${anchor}`;
965963
});
966964

967965
// Quote reply

0 commit comments

Comments
 (0)