summaryrefslogtreecommitdiff
path: root/xml/impl/src/com/intellij/codeInsight
diff options
context:
space:
mode:
Diffstat (limited to 'xml/impl/src/com/intellij/codeInsight')
-rw-r--r--xml/impl/src/com/intellij/codeInsight/completion/HtmlTextCompletionConfidence.java4
-rw-r--r--xml/impl/src/com/intellij/codeInsight/template/emmet/filters/TrimZenCodingFilter.java25
2 files changed, 21 insertions, 8 deletions
diff --git a/xml/impl/src/com/intellij/codeInsight/completion/HtmlTextCompletionConfidence.java b/xml/impl/src/com/intellij/codeInsight/completion/HtmlTextCompletionConfidence.java
index ec6c806ffa1f..6d95604dc077 100644
--- a/xml/impl/src/com/intellij/codeInsight/completion/HtmlTextCompletionConfidence.java
+++ b/xml/impl/src/com/intellij/codeInsight/completion/HtmlTextCompletionConfidence.java
@@ -33,7 +33,9 @@ public class HtmlTextCompletionConfidence extends CompletionConfidence {
if (node != null && node.getElementType() == XmlTokenType.XML_DATA_CHARACTERS) {
PsiElement parent = contextElement.getParent();
if (parent instanceof XmlText || parent instanceof XmlDocument) {
- String prefix = contextElement.getText().substring(0, offset - contextElement.getTextRange().getStartOffset());
+ String contextElementText = contextElement.getText();
+ int endOffset = offset - contextElement.getTextRange().getStartOffset();
+ String prefix = contextElementText.substring(0, Math.min(contextElementText.length(), endOffset));
if (!StringUtil.startsWithChar(prefix, '<') && !StringUtil.startsWithChar(prefix, '&')) {
return ThreeState.YES;
}
diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/filters/TrimZenCodingFilter.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/filters/TrimZenCodingFilter.java
index ceb0d1dd61b9..421fbdd46564 100644
--- a/xml/impl/src/com/intellij/codeInsight/template/emmet/filters/TrimZenCodingFilter.java
+++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/filters/TrimZenCodingFilter.java
@@ -18,6 +18,7 @@ package com.intellij.codeInsight.template.emmet.filters;
import com.intellij.codeInsight.template.emmet.nodes.GenerationNode;
import com.intellij.codeInsight.template.emmet.tokens.TemplateToken;
import com.intellij.lang.xml.XMLLanguage;
+import com.intellij.openapi.application.ApplicationManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.XmlElementVisitor;
import com.intellij.psi.xml.XmlDocument;
@@ -25,6 +26,7 @@ import com.intellij.psi.xml.XmlTag;
import com.intellij.psi.xml.XmlTagValue;
import org.jetbrains.annotations.NotNull;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
@@ -57,18 +59,27 @@ public class TrimZenCodingFilter extends ZenCodingFilter {
if (document != null) {
XmlTag tag = document.getRootTag();
if (tag != null && !tag.getText().isEmpty()) {
- new XmlElementVisitor() {
+ tag.accept(new XmlElementVisitor() {
@Override
- public void visitXmlTag(XmlTag tag) {
- if(!tag.isEmpty()) {
- XmlTagValue tagValue = tag.getValue();
- tagValue.setText(PATTERN.matcher(tagValue.getText()).replaceAll(""));
+ public void visitXmlTag(final XmlTag tag) {
+ if (!tag.isEmpty()) {
+ final XmlTagValue tagValue = tag.getValue();
+ final Matcher matcher = PATTERN.matcher(tagValue.getText());
+ if (matcher.matches()) {
+ ApplicationManager.getApplication().runWriteAction(new Runnable() {
+ @Override
+ public void run() {
+ tagValue.setText(matcher.replaceAll(""));
+ }
+ });
+ }
}
tag.acceptChildren(this);
}
- }.visitXmlTag(tag);
+ });
return tag.getText();
- } else {
+ }
+ else {
return PATTERN.matcher(document.getText()).replaceAll("");
}
}