diff --git a/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/LocalHistoryActivityProvider.kt b/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/LocalHistoryActivityProvider.kt index 8e23e8e001f9..cb4dff86b819 100644 --- a/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/LocalHistoryActivityProvider.kt +++ b/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/LocalHistoryActivityProvider.kt @@ -6,6 +6,7 @@ import com.intellij.history.ActivityPresentationProvider import com.intellij.history.core.* import com.intellij.history.core.changes.ChangeSet import com.intellij.history.core.changes.PutLabelChange +import com.intellij.history.integration.CommonActivity import com.intellij.history.integration.IdeaGateway import com.intellij.history.integration.LocalHistoryImpl import com.intellij.openapi.extensions.ExtensionPointName @@ -64,17 +65,25 @@ internal class LocalHistoryActivityProvider(val project: Project, private val ga private fun doLoadPathActivityList(projectId: String, scope: ActivityScope, path: String, scopeFilter: String?, affectedPaths: MutableSet, activityItems: MutableList) { - var lastLabel: ChangeSet? = null + var lastEventLabel: ChangeSet? = null + val userLabels = mutableListOf() facade.collectChanges(path, ChangeAndPathProcessor(projectId, scopeFilter, affectedPaths::add) { changeSet -> if (changeSet.isSystemLabelOnly) return@ChangeAndPathProcessor if (changeSet.isLabelOnly) { - lastLabel = changeSet + if (changeSet.activityId == CommonActivity.UserLabel) { + userLabels.add(changeSet) + lastEventLabel = null + } else { + lastEventLabel = changeSet + } } else { - if (lastLabel != null) { - activityItems.add(lastLabel!!.toActivityItem(scope)) - lastLabel = null - } + if (userLabels.isNotEmpty()) activityItems.addAll(userLabels.map { it.toActivityItem(scope) }) + if (lastEventLabel != null) activityItems.add(lastEventLabel!!.toActivityItem(scope)) + + userLabels.clear() + lastEventLabel = null + activityItems.add(changeSet.toActivityItem(scope)) } }) diff --git a/platform/lvcs-impl/testSrc/com/intellij/platform/lvcs/impl/LocalHistoryActivityProviderTest.kt b/platform/lvcs-impl/testSrc/com/intellij/platform/lvcs/impl/LocalHistoryActivityProviderTest.kt index e1245f3a94c3..9d7a4727b2e5 100644 --- a/platform/lvcs-impl/testSrc/com/intellij/platform/lvcs/impl/LocalHistoryActivityProviderTest.kt +++ b/platform/lvcs-impl/testSrc/com/intellij/platform/lvcs/impl/LocalHistoryActivityProviderTest.kt @@ -1,6 +1,7 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.platform.lvcs.impl +import com.intellij.history.ActivityId import com.intellij.history.LocalHistory import com.intellij.history.integration.IntegrationTestCase import com.intellij.testFramework.HeavyPlatformTestCase @@ -61,6 +62,41 @@ class LocalHistoryActivityProviderTest : IntegrationTestCase() { TestCase.assertTrue(labelNames.intersect(listOf(systemLabel, hiddenUserLabel1, hiddenUserLabel2)).isEmpty()) } + fun `test multiple event and user labels`() { + val file = createFile("file.txt") + + val activityId = ActivityId("dummyProvider", "dummyActivity") + val localHistory = LocalHistory.getInstance() + + setContent(file, "initial") + val visibleEventLabel1 = "visible event label 1" + localHistory.putEventLabel(project, visibleEventLabel1, activityId) + val userLabel1 = "user label 1" + localHistory.putUserLabel(project, userLabel1) + localHistory.putEventLabel(project, "event label 1", activityId) + val userLabel2 = "user label 2" + localHistory.putUserLabel(project, userLabel2) + + setContent(file, "content1") + val visibleEventLabel2 = "visible event label 2" + localHistory.putEventLabel(project, visibleEventLabel2, activityId) + localHistory.putEventLabel(project, "hidden event label 1", activityId) + + setContent(file, "content2") + val userLabel3 = "user label 3" + localHistory.putUserLabel(project, userLabel3) + localHistory.putEventLabel(project, "hidden event label 2", activityId) + localHistory.putEventLabel(project, "hidden event label 3", activityId) + + val provider = LocalHistoryActivityProvider(project, gateway) + val scope = ActivityScope.fromFile(file) + + val activityList = provider.loadActivityList(scope, null) + val labelNames = activityList.getLabelNameSet() + + TestCase.assertEquals(listOf(userLabel1, userLabel2, userLabel3, visibleEventLabel1, visibleEventLabel2), labelNames.toList().sorted()) + } + fun `test directory`() { val directory = createDirectory("directory") val file = createChildData(directory, "file.txt")