From dd5059236f799e9e70dc79efc972284fae940f63 Mon Sep 17 00:00:00 2001 From: Valeria Golovina Date: Fri, 10 Jul 2026 15:25:13 +0300 Subject: [PATCH] [gitlab] comments navigation for many drafts in the same position Use correct comparator for DiscussionIdAndMappedPosition to avoid missing drafts if they are attached to the same line Fixed IJPL-249453 GitOrigin-RevId: 9a48e9c9b10c9dde4e8db3a0ff47ecd00a5110d2 --- ...GitLabMergeRequestDiscussionsViewModels.kt | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/plugins/gitlab/gitlab-core/src/org/jetbrains/plugins/gitlab/mergerequest/ui/review/GitLabMergeRequestDiscussionsViewModels.kt b/plugins/gitlab/gitlab-core/src/org/jetbrains/plugins/gitlab/mergerequest/ui/review/GitLabMergeRequestDiscussionsViewModels.kt index 4830280cdb19..e3a2c1b6a0e1 100644 --- a/plugins/gitlab/gitlab-core/src/org/jetbrains/plugins/gitlab/mergerequest/ui/review/GitLabMergeRequestDiscussionsViewModels.kt +++ b/plugins/gitlab/gitlab-core/src/org/jetbrains/plugins/gitlab/mergerequest/ui/review/GitLabMergeRequestDiscussionsViewModels.kt @@ -238,25 +238,22 @@ internal class GitLabMergeRequestDiscussionsViewModelsImpl( lookupAdjacentComment(currentThreadId, isNext = false, isVisible) private fun lookupAdjacentComment(cursorLocation: UnifiedCodeReviewItemPosition, isNext: Boolean, isVisible: (String) -> Boolean): String? { - // Fetch stuff val threads = allDiscussionsOrder.value ?: return null if (threads.isEmpty()) return null // Search from before the first comment on the selected line - var location: DiscussionIdAndMappedPosition? = DiscussionIdAndMappedPosition(null, Date.from(EPOCH), cursorLocation) + val cursorPosition = DiscussionIdAndMappedPosition("", Date.from(EPOCH), cursorLocation) - // Find the next or previous comment - location = when (isNext) { - true -> threads.ceiling(location) - false -> threads.floor(location) + val adjacentThread = when (isNext) { + true -> threads.ceiling(cursorPosition) + false -> threads.floor(cursorPosition) } + if (adjacentThread == null) return null - return if (location?.id == null || isVisible(location.id)) { - return location?.id - } - else { - lookupAdjacentComment(location.id, isNext, isVisible) + return if (isVisible(adjacentThread.id)) { + adjacentThread.id } + else lookupAdjacentComment(adjacentThread.id, isNext, isVisible) } private fun lookupAdjacentComment(currentThreadId: String, isNext: Boolean, isVisible: (String) -> Boolean): String? { @@ -307,8 +304,10 @@ internal class GitLabMergeRequestDiscussionsViewModelsImpl( )) } }) { locations -> + // the same date will be used for all drafts when they are loaded from gitlab server, so ids are important TreeSet(Comparator { left, right -> comparator.compare(left.mappedPosition, right.mappedPosition) } - .thenComparing { left, right -> left.createdAt.compareTo(right.createdAt) }) + .thenComparing { left, right -> left.createdAt.compareTo(right.createdAt) } + .thenComparing { left, right -> left.id.compareTo(right.id) }) .apply { addAll(locations.filterNotNull()) } } } @@ -338,7 +337,7 @@ private data class IntermediateDiscussionData( ) private data class DiscussionIdAndMappedPosition( - val id: String?, + val id: String, val createdAt: Date, val mappedPosition: UnifiedCodeReviewItemPosition, ) \ No newline at end of file