From bce7f14a93a1bce8abd7386972eaabd321d682e9 Mon Sep 17 00:00:00 2001 From: Rustam Vishnyakov Date: Mon, 20 Jun 2016 14:58:22 +0300 Subject: [PATCH] Performance fix: don't reformat code style sample twice upon first preview load (see IDEA-127086 Code Style preview: too much delay) --- .../application/options/CodeStyleAbstractPanel.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java b/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java index a5dce18bd9cc..962c991d9de8 100644 --- a/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java @@ -202,7 +202,9 @@ public abstract class CodeStyleAbstractPanel implements Disposable { ApplicationManager.getApplication().runWriteAction(() -> { try { Document beforeReformat = null; - beforeReformat = collectChangesBeforeCurrentSettingsAppliance(project); + if (myEditor.getDocument().getTextLength() > 0) { + beforeReformat = collectChangesBeforeCurrentSettingsAppliance(project); + } //important not mark as generated not to get the classes before setting language level PsiFile psiFile = createFileFromText(project, myTextToReformat); @@ -227,7 +229,7 @@ public abstract class CodeStyleAbstractPanel implements Disposable { myEditor.getSettings().setTabSize(clone.getTabSize(getFileType())); Document document = myEditor.getDocument(); document.replaceString(0, document.getTextLength(), formatted.getText()); - if (document != null && beforeReformat != null) { + if (beforeReformat != null) { highlightChanges(beforeReformat); } }