diff --git a/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListenerCompat.kt b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListenerCompat.kt index aacd0e69d70..9c6521beb74 100644 --- a/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListenerCompat.kt +++ b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListenerCompat.kt @@ -340,7 +340,11 @@ val KtFile.inBlockModifications: Collection private fun KtFile.addInBlockModifiedItem(element: KtElement) { val collection = putUserDataIfAbsent(IN_BLOCK_MODIFICATIONS, mutableSetOf()) synchronized(collection) { - collection.add(element) + val needToAddBlock = collection.none { it.isAncestor(element, strict = false) } + if (needToAddBlock) { + collection.removeIf { element.isAncestor(it, strict = false) } + collection.add(element) + } } val count = getUserData(FILE_IN_BLOCK_MODIFICATION_COUNT) ?: 0 putUserData(FILE_IN_BLOCK_MODIFICATION_COUNT, count + 1)