Merge branch 'mskr/webstorm-js-bugs'
authorMaxim Kropotov <maxim.kropotov@jetbrains.com>
Thu, 10 Nov 2016 13:48:16 +0000 (16:48 +0300)
committerMaxim Kropotov <maxim.kropotov@jetbrains.com>
Thu, 10 Nov 2016 13:48:16 +0000 (16:48 +0300)
platform/lang-impl/src/com/intellij/codeInsight/editorActions/enter/EnterBetweenBracesHandler.java

index 70e3526de12723d01138bd6332dc675c28558f36..d5b0028500860524486b3a808e1368ec4a287cd9 100644 (file)
@@ -25,10 +25,12 @@ import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Ref;
+import com.intellij.psi.PsiComment;
 import com.intellij.psi.PsiDocumentManager;
 import com.intellij.psi.PsiFile;
 import com.intellij.psi.codeStyle.CodeStyleManager;
 import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
+import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.util.IncorrectOperationException;
 import com.intellij.util.text.CharArrayUtil;
 import org.jetbrains.annotations.NotNull;
@@ -65,7 +67,7 @@ public class EnterBetweenBracesHandler extends EnterHandlerDelegateAdapter {
       CodeDocumentationUtil.tryParseCommentContext(file, text, caretOffset, start);
 
     // special case: enter inside "()" or "{}"
-    String indentInsideJavadoc = commentContext.docAsterisk
+    String indentInsideJavadoc = isInComment(caretOffset, file) && commentContext.docAsterisk
                                  ? CodeDocumentationUtil.getIndentInsideJavadoc(document, caretOffset)
                                  : null;
 
@@ -86,6 +88,10 @@ public class EnterBetweenBracesHandler extends EnterHandlerDelegateAdapter {
     return indentInsideJavadoc == null ? Result.Continue : Result.DefaultForceIndent;
   }
 
+  private static boolean isInComment(int offset, PsiFile file) {
+    return PsiTreeUtil.getParentOfType(file.findElementAt(offset), PsiComment.class)!=null;
+  }
+
   private static boolean isValidOffset(int offset, CharSequence text) {
     return offset >= 0 && offset < text.length();
   }