zen coding should work in html context of php file, tests
authorEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Tue, 20 Apr 2010 12:22:22 +0000 (16:22 +0400)
committerEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Tue, 20 Apr 2010 12:22:22 +0000 (16:22 +0400)
xml/impl/src/com/intellij/codeInsight/template/zencoding/XmlZenCodingTemplate.java

index 1caf964394311875e6baaec2c6af8bc25d909cee..8ea46618e0cf3e269f6e9e86d295706172773502 100644 (file)
@@ -21,6 +21,7 @@ import com.intellij.codeInsight.template.CustomLiveTemplate;
 import com.intellij.codeInsight.template.CustomTemplateCallback;
 import com.intellij.codeInsight.template.TemplateInvokationListener;
 import com.intellij.codeInsight.template.impl.TemplateImpl;
+import com.intellij.lang.injection.InjectedLanguageManager;
 import com.intellij.lang.xml.XMLLanguage;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.command.CommandProcessor;
@@ -349,9 +350,19 @@ public class XmlZenCodingTemplate implements CustomLiveTemplate {
     if (!webEditorOptions.isZenCodingEnabled()) {
       return false;
     }
-    PsiElement element = InjectedLanguageUtil.findElementAtNoCommit(file, offset > 0 ? offset - 1 : offset);
+    if (file == null) {
+      return false;
+    }
+    PsiDocumentManager.getInstance(file.getProject()).commitAllDocuments();
+    PsiElement element = null;
+    if (!InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file)) {
+      element = InjectedLanguageUtil.findInjectedElementNoCommit(file, offset);
+    }
     if (element == null) {
-      element = file;
+      element = file.findElementAt(offset > 0 ? offset - 1 : offset);
+      if (element == null) {
+        element = file;
+      }
     }
     if (element.getLanguage() instanceof XMLLanguage) {
       if (PsiTreeUtil.getParentOfType(element, XmlAttributeValue.class) != null) {