mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Emmet: fix implicit attributes expansion
This commit is contained in:
@@ -159,6 +159,14 @@
|
||||
<option name="HTML_TEXT" value="true"/>
|
||||
</context>
|
||||
</template>
|
||||
<template description="<link rel="import" href="">"
|
||||
name="link:import" toReformat="true" toShortenFQNames="true"
|
||||
value="<link rel="import" href="$HTML$.html"/>">
|
||||
<variable alwaysStopAt="true" defaultValue="""" expression="" name="HTML"/>
|
||||
<context>
|
||||
<option name="HTML_TEXT" value="true"/>
|
||||
</context>
|
||||
</template>
|
||||
<template description="<link rel="import" href="">"
|
||||
name="link:im" toReformat="true" toShortenFQNames="true"
|
||||
value="<link rel="import" href="$HTML$.html"/>">
|
||||
@@ -397,13 +405,13 @@
|
||||
<option name="HTML_TEXT" value="true"/>
|
||||
</context>
|
||||
</template>
|
||||
<template description="<input name="..." type="hidden"/>" name="input:hidden" toReformat="true" toShortenFQNames="true" value="<input name="$VAR0$" type="hidden"/>">
|
||||
<template description="<input type="hidden" name="..."/>" name="input:hidden" toReformat="true" toShortenFQNames="true" value="<input type="hidden" name="$VAR0$" />">
|
||||
<variable alwaysStopAt="true" defaultValue="""" expression="" name="VAR0"/>
|
||||
<context>
|
||||
<option name="HTML_TEXT" value="true"/>
|
||||
</context>
|
||||
</template>
|
||||
<template description="<input name="..." type="hidden"/>" name="input:h" toReformat="true" toShortenFQNames="true" value="<input name="$VAR0$" type="hidden"/>">
|
||||
<template description="<input type="hidden" name="..."/>" name="input:h" toReformat="true" toShortenFQNames="true" value="<input type="hidden" name="$VAR0$"/>">
|
||||
<variable alwaysStopAt="true" defaultValue="""" expression="" name="VAR0"/>
|
||||
<context>
|
||||
<option name="HTML_TEXT" value="true"/>
|
||||
|
||||
@@ -22,13 +22,9 @@ import com.intellij.openapi.command.undo.UndoConstants;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.psi.XmlElementFactory;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.LocalTimeCounter;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -100,7 +96,7 @@ public class TemplateToken extends ZenCodingToken {
|
||||
String templateString = template.getString();
|
||||
final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(callback.getProject());
|
||||
if (!containsAttrsVar(template)) {
|
||||
XmlFile dummyFile = (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.XML, templateString);
|
||||
XmlFile dummyFile = (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.HTML, templateString);
|
||||
dummyRootTag = dummyFile.getRootTag();
|
||||
if (dummyRootTag != null) {
|
||||
addMissingAttributes(dummyRootTag, attributes);
|
||||
@@ -119,30 +115,14 @@ public class TemplateToken extends ZenCodingToken {
|
||||
|
||||
|
||||
private static void addMissingAttributes(@NotNull XmlTag tag, @NotNull Map<String, String> attributes) {
|
||||
Map<String, String> missingAttributes = ContainerUtil.newLinkedHashMap();
|
||||
for (Map.Entry<String, String> attribute : attributes.entrySet()) {
|
||||
if (!XmlEmmetParser.DEFAULT_ATTRIBUTE_NAME.equals(attribute.getKey()) && tag.getAttribute(attribute.getKey()) == null) {
|
||||
missingAttributes.put(attribute.getKey(), attribute.getValue());
|
||||
}
|
||||
}
|
||||
addAttributesBefore(tag, missingAttributes);
|
||||
}
|
||||
|
||||
|
||||
private static void addAttributesBefore(@NotNull XmlTag tag, @NotNull Map<String, String> attributes) {
|
||||
XmlAttribute firstAttribute = ArrayUtil.getFirstElement(tag.getAttributes());
|
||||
XmlElementFactory factory = XmlElementFactory.getInstance(tag.getProject());
|
||||
for (String name : attributes.keySet()) {
|
||||
XmlAttribute xmlAttribute = factory.createXmlAttribute(name, "");
|
||||
if (firstAttribute != null) {
|
||||
tag.addBefore(xmlAttribute, firstAttribute);
|
||||
}
|
||||
else {
|
||||
tag.add(xmlAttribute);
|
||||
tag.setAttribute(attribute.getKey(), "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public TemplateImpl getTemplate() {
|
||||
return myTemplate;
|
||||
|
||||
Reference in New Issue
Block a user