From 2e49c8b90413fc5afaf1202c8196958cb991a557 Mon Sep 17 00:00:00 2001 From: Rustam Vishnyakov Date: Mon, 24 Oct 2016 17:38:49 +0300 Subject: [PATCH] Adjust indent synchronously on relatively small files --- .../lineIndent/FormatterBasedIndentAdjuster.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/lineIndent/FormatterBasedIndentAdjuster.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/lineIndent/FormatterBasedIndentAdjuster.java index cbd8da60ab39..e89f855a349d 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/lineIndent/FormatterBasedIndentAdjuster.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/lineIndent/FormatterBasedIndentAdjuster.java @@ -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; -- 2.32.0