fixed injected css formatting
authorMaxim.Mossienko <Maxim.Mossienko@jetbrains.com>
Mon, 26 Apr 2010 14:03:19 +0000 (18:03 +0400)
committerMaxim.Mossienko <Maxim.Mossienko@jetbrains.com>
Mon, 26 Apr 2010 14:51:09 +0000 (18:51 +0400)
xml/impl/src/com/intellij/psi/formatter/xml/XmlTagBlock.java

index f703da01066a9aa99ef31146e2d8b4c7d5ae0482..1e53cbb9e1078d24b21a147ccec5d5ac7198f053 100644 (file)
@@ -21,13 +21,13 @@ import com.intellij.lang.Language;
 import com.intellij.lang.LanguageFormatting;
 import com.intellij.openapi.util.Ref;
 import com.intellij.openapi.util.TextRange;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiFile;
-import com.intellij.psi.PsiLanguageInjectionHost;
-import com.intellij.psi.tree.IElementType;
+import com.intellij.psi.*;
 import com.intellij.psi.formatter.FormatterUtil;
+import com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider;
+import com.intellij.psi.tree.IElementType;
 import com.intellij.psi.xml.XmlElementType;
 import com.intellij.psi.xml.XmlTag;
+import com.intellij.psi.xml.XmlToken;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -221,6 +221,26 @@ public class XmlTagBlock extends AbstractXmlBlock{
         return true;
       }
     }
+    
+    PsiFile containingFile = child.getPsi().getContainingFile();
+    FileViewProvider fileViewProvider = containingFile.getViewProvider();
+    
+    if (fileViewProvider instanceof TemplateLanguageFileViewProvider) {
+      Language templateLanguage = ((TemplateLanguageFileViewProvider)fileViewProvider).getTemplateDataLanguage();
+      PsiElement at = fileViewProvider.findElementAt(child.getStartOffset(), templateLanguage);
+
+      if (at instanceof XmlToken) {
+        at = at.getParent();
+      }
+      
+      // TODO: several comments
+      if (at instanceof PsiComment && 
+          at.getTextRange().equals(child.getTextRange()) && 
+          at.getNode() != child) {
+        return buildInjectedPsiBlocks(result, at.getNode(), wrap, alignment, indent);
+      }
+    }
+
     return false;
   }