Hi,
I got this error
Fold regions must be collapsed or expanded inside batchFoldProcessing() only
Here’s part of my code
private fun foldOldBlocks() {
val now = System.currentTimeMillis()
if (lastAgeUpdate == 0L) {
lastAgeUpdate = now
}
ages.entries.map { ages[it.key] = ages[it.key]!! + now - lastAgeUpdate }
lastAgeUpdate = now
// get ages older than 3 seconds
val oldBlocks = ages.entries.filter { it.value > 3000 }
val fileBlocksMap = mutableMapOf<String, List<FoldRegion>>()
val blockHashMap = mutableMapOf<String, Int>()
ApplicationManager.getApplication().invokeAndWait {
run {
WriteCommandAction.runWriteCommandAction(project) {
oldBlocks.forEach {
val parts = it.key.split(":")
val filePath = parts[0]
val hash = parts[1].toInt()
var found = false
val foldingBlocks = fileBlocksMap.getOrDefault(filePath, getFoldingBlocksForFile(filePath))
foldingBlocks.forEach { foldRegion ->
val blockKey = filePath + ":" + foldRegion.startOffset + ":" + foldRegion.endOffset
val contentHash = blockHashMap.getOrDefault(blockKey, getFoldingRegionHash(foldRegion))
if (contentHash == hash) {
if (foldRegion.isExpanded) {
foldRegion.isExpanded = false
}
ages.remove(it.key)
found = true
return@forEach
}
}
if (!found) {
// cleanup
ages.remove(it.key)
}
}
}
}
}
}
I couldn’t find a way to use batchFoldProcessing
Please advise
Thank you very much