Fixed keeping of folded state for imports on optimize
This commit is contained in:
@@ -149,14 +149,17 @@ public class KotlinImportOptimizer() : ImportOptimizer {
|
|||||||
//TODO: do not touch file if everything is already correct?
|
//TODO: do not touch file if everything is already correct?
|
||||||
|
|
||||||
ApplicationManager.getApplication()!!.runWriteAction(Runnable {
|
ApplicationManager.getApplication()!!.runWriteAction(Runnable {
|
||||||
for (import in file.getImportDirectives()) {
|
// remove old imports after adding new ones to keep imports folding state
|
||||||
import.delete()
|
val oldImports = file.getImportDirectives()
|
||||||
}
|
|
||||||
|
|
||||||
val importList = file.getImportList()!!
|
val importList = file.getImportList()!!
|
||||||
val psiFactory = JetPsiFactory(file.getProject())
|
val psiFactory = JetPsiFactory(file.getProject())
|
||||||
for (importPath in sortedImportsToGenerate) {
|
for (importPath in sortedImportsToGenerate) {
|
||||||
importList.add(psiFactory.createImportDirective(importPath))
|
importList.addBefore(psiFactory.createImportDirective(importPath), oldImports.lastOrNull()) // insert into the middle to keep collapsed state
|
||||||
|
}
|
||||||
|
|
||||||
|
for (import in oldImports) {
|
||||||
|
import.delete()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user