Adjust indent synchronously on relatively small files
[idea/community.git] / platform / lang-impl / src / com / intellij / psi / impl / source / codeStyle / lineIndent / FormatterBasedIndentAdjuster.java
index cbd8da60ab396642ee653013dcf0192a9773e23f..e89f855a349ddcf556819648291a2b5b8dbc9496 100644 (file)
@@ -24,6 +24,8 @@ import com.intellij.psi.codeStyle.CodeStyleManager;
 import org.jetbrains.annotations.NotNull;
 
 public class FormatterBasedIndentAdjuster  {
+  
+  private final static int MAX_SYNCHRONOUS_ADJUSTMENT_DOC_SIZE = 100000;
 
   private FormatterBasedIndentAdjuster() {
   }
@@ -33,7 +35,7 @@ public class FormatterBasedIndentAdjuster  {
                                               int myOffset) {
     IndentAdjusterRunnable fixer = new IndentAdjusterRunnable(myProject, myDocument, myOffset);
     PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
-    if (ApplicationManager.getApplication().isUnitTestMode()) {
+    if (isSynchronousAdjustment(myDocument)) {
       documentManager.commitDocument(myDocument);
       fixer.run();
     }
@@ -42,6 +44,10 @@ public class FormatterBasedIndentAdjuster  {
     }
   }
   
+  private static boolean isSynchronousAdjustment(@NotNull Document document) {
+    return ApplicationManager.getApplication().isUnitTestMode() || document.getTextLength() <= MAX_SYNCHRONOUS_ADJUSTMENT_DOC_SIZE;
+  }
+  
   public static class IndentAdjusterRunnable implements Runnable {
     private Project myProject;
     private int myLine;