use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.
the class HtmlScriptLanguageInjector method getLanguagesToInject.
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement host) {
if (!host.isValid() || !(host instanceof XmlText) || !HtmlUtil.isHtmlTagContainingFile(host)) {
return;
}
XmlTag scriptTag = ((XmlText) host).getParentTag();
if (scriptTag == null) {
return;
}
final Language language = getScriptLanguageToInject(scriptTag);
if (language == null || HtmlScriptInjectionBlockerExtension.isInjectionBlocked(scriptTag, language)) {
return;
}
if (LanguageUtil.isInjectableLanguage(language)) {
registrar.startInjecting(language).addPlace(null, null, (PsiLanguageInjectionHost) host, TextRange.create(0, host.getTextLength())).doneInjecting();
}
}
use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.
the class XmlTagWriteTest method test3.
public void test3() throws Exception {
final XmlTag tag = XmlElementFactory.getInstance(getProject()).createTagFromText("<b>\n0123456</b>");
final XmlText text = (XmlText) tag.getValue().getChildren()[0];
String textS = text.getText();
ApplicationManager.getApplication().runWriteAction(() -> text.insertText("lala", 2));
XmlText text2 = (XmlText) tag.getValue().getChildren()[0];
assertEquals(textS.substring(0, 2) + "lala" + textS.substring(2), text2.getText());
}
use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.
the class XmlTagManipulator method getRangeInElement.
@Override
@NotNull
public TextRange getRangeInElement(@NotNull final XmlTag tag) {
if (tag.getSubTags().length > 0) {
// Text range in tag with subtags is not supported, return empty range, consider making this function nullable.
return TextRange.EMPTY_RANGE;
}
final XmlTagValue value = tag.getValue();
final XmlText[] texts = value.getTextElements();
switch(texts.length) {
case 0:
return value.getTextRange().shiftRight(-tag.getTextOffset());
case 1:
return getValueRange(texts[0]);
default:
return TextRange.EMPTY_RANGE;
}
}
use of com.intellij.psi.xml.XmlText in project oxy-template-support-plugin by mutant-industries.
the class OxyTemplateInjectedBlockBuilder method buildInjectedBlocks.
@Nullable
public ASTNode buildInjectedBlocks(@NotNull List<Block> result, @NotNull ASTNode injectedNode, @Nullable Indent indent, @NotNull final TextRange allowedRange) {
FileViewProvider viewProvider = injectedNode.getPsi().getContainingFile().getViewProvider();
TextRange allowedRangeLocal = allowedRange;
PsiElement elementAt = viewProvider.findElementAt(injectedNode.getStartOffset(), HTMLLanguage.INSTANCE);
while (elementAt != null) {
if (elementAt.getNode().getElementType() == getOuterLanguageElement()) {
break;
} else if (!allowedRangeLocal.contains(elementAt.getTextRange())) {
/**
* It is important to cover all content within allowedRange. When the current element doesn't fit in
* (e.g. unclosed tags etc.), let's just try it's first child.
*/
while (elementAt.getFirstChild() != null && !allowedRangeLocal.contains((elementAt = elementAt.getFirstChild()).getTextRange())) ;
}
/**
* shift to topmost element, that covers the range, e.g.:
* ...html...<m:foo... - T_XML_TAG_START -> MACRO_[EMPTY_]TAG
*/
while (OxyTemplateHelper.checkRangeContainsParent(elementAt, allowedRangeLocal, getOuterLanguageElement())) {
elementAt = elementAt.getParent();
}
if (!FormatterUtil.containsWhiteSpacesOnly(elementAt.getNode())) {
TextRange intersection = elementAt.getNode().getTextRange().intersection(allowedRangeLocal);
assert intersection != null;
result.add(createInjectedBlock(elementAt.getNode(), null, null, indent, intersection));
}
while (elementAt.getNextSibling() == null && !(elementAt.getParent() instanceof XmlDocumentImpl)) {
elementAt = elementAt.getParent();
}
elementAt = elementAt.getNextSibling();
if (elementAt != null) {
if (elementAt instanceof XmlText && OxyTemplateHelper.containsElement(elementAt, allowedRangeLocal, getOuterLanguageElement())) {
elementAt = elementAt.getFirstChild();
}
if (elementAt.getNode().getStartOffset() >= allowedRange.getEndOffset()) {
break;
}
allowedRangeLocal = TextRange.create(elementAt.getNode().getStartOffset(), allowedRange.getEndOffset());
}
}
return shiftOriginalNode(injectedNode, result);
}
Aggregations