From 6fca237f5c2a9dff656b6b3ed10626aa10c98153 Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Thu, 22 Apr 2010 21:50:34 +0400 Subject: [PATCH] zen-coding: default DIV tag support in HTML/XHTML files; tests --- .../zencoding/XmlZenCodingTemplate.java | 20 +++++++++++++++++++ .../template/zencoding/ZenCodingTemplate.java | 3 --- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/xml/impl/src/com/intellij/codeInsight/template/zencoding/XmlZenCodingTemplate.java b/xml/impl/src/com/intellij/codeInsight/template/zencoding/XmlZenCodingTemplate.java index 7f6b294d6b8a..ab40993e31d7 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/zencoding/XmlZenCodingTemplate.java +++ b/xml/impl/src/com/intellij/codeInsight/template/zencoding/XmlZenCodingTemplate.java @@ -46,6 +46,7 @@ public class XmlZenCodingTemplate extends ZenCodingTemplate { private static final String SELECTORS = ".#["; private static final String ID = "id"; private static final String CLASS = "class"; + private static final String DEFAULT_TAG = "div"; private static String getPrefix(@NotNull String templateKey) { for (int i = 0, n = templateKey.length(); i < n; i++) { @@ -160,10 +161,26 @@ public class XmlZenCodingTemplate extends ZenCodingTemplate { return type == StdFileTypes.XHTML || type == StdFileTypes.JSPX || type == StdFileTypes.XML; } + private static boolean isHtml(CustomTemplateCallback callback) { + FileType type = callback.getFileType(); + return type == StdFileTypes.HTML || type == StdFileTypes.XHTML; + } + @Override @Nullable protected TemplateToken parseTemplateKey(String key, CustomTemplateCallback callback) { String prefix = getPrefix(key); + boolean useDefaultTag = false; + if (prefix.length() == 0) { + if (!isHtml(callback)) { + return null; + } + else { + useDefaultTag = true; + prefix = DEFAULT_TAG; + key = prefix + key; + } + } TemplateImpl template = callback.findApplicableTemplate(prefix); if (template == null && !isXML11ValidQName(prefix)) { return null; @@ -172,6 +189,9 @@ public class XmlZenCodingTemplate extends ZenCodingTemplate { if (token == null) { return null; } + if (useDefaultTag && token.myAttribute2Value.size() == 0) { + return null; + } if (template != null && (token.myAttribute2Value.size() > 0 || isTrueXml(callback))) { assert prefix.equals(token.myKey); token.myTemplate = template; diff --git a/xml/impl/src/com/intellij/codeInsight/template/zencoding/ZenCodingTemplate.java b/xml/impl/src/com/intellij/codeInsight/template/zencoding/ZenCodingTemplate.java index d156b1f54f61..9f0257f01e25 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/zencoding/ZenCodingTemplate.java +++ b/xml/impl/src/com/intellij/codeInsight/template/zencoding/ZenCodingTemplate.java @@ -68,9 +68,6 @@ public abstract class ZenCodingTemplate implements CustomLiveTemplate { result.add(new NumberToken(num)); } else { - if (key.length() == 0) { - return null; - } TemplateToken token = parseTemplateKey(key, callback); if (token == null) return null; result.add(token);