use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.
the class UserColorLookup method handleUserSelection.
private static void handleUserSelection(InsertionContext context, @NotNull Function<Color, String> colorToStringConverter) {
Project project = context.getProject();
Editor editor = context.getEditor();
int startOffset = context.getStartOffset();
context.getDocument().deleteString(startOffset, context.getTailOffset());
PsiElement element = context.getFile().findElementAt(editor.getCaretModel().getOffset());
Color myColorAtCaret = element instanceof XmlToken ? getColorFromElement(element) : null;
context.setLaterRunnable(() -> {
if (editor.isDisposed() || project.isDisposed())
return;
List<ColorPickerListener> listeners = ColorPickerListenerFactory.createListenersFor(element);
Color color = ColorChooser.chooseColor(WindowManager.getInstance().suggestParentWindow(project), XmlBundle.message("choose.color.dialog.title"), myColorAtCaret, true, listeners, true);
if (color != null) {
WriteCommandAction.runWriteCommandAction(project, () -> {
editor.getCaretModel().moveToOffset(startOffset);
EditorModificationUtil.insertStringAtCaret(editor, colorToStringConverter.fun(color));
});
}
});
}
use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.
the class XmlTokenManipulator method handleContentChange.
@Override
public XmlToken handleContentChange(@NotNull XmlToken xmlToken, @NotNull TextRange range, String newContent) throws IncorrectOperationException {
String oldText = xmlToken.getText();
String newText = oldText.substring(0, range.getStartOffset()) + newContent + oldText.substring(range.getEndOffset());
IElementType tokenType = xmlToken.getTokenType();
FileElement holder = DummyHolderFactory.createHolder(xmlToken.getManager(), null).getTreeElement();
LeafElement leaf = ASTFactory.leaf(tokenType, holder.getCharTable().intern(newText));
holder.rawAddChildren(leaf);
return (XmlToken) xmlToken.replace(leaf.getPsi());
}
use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.
the class HtmlClosingTagErrorFilter method shouldHighlightErrorElement.
@Override
public boolean shouldHighlightErrorElement(@NotNull final PsiErrorElement element) {
final PsiFile psiFile = element.getContainingFile();
if (psiFile == null || psiFile.getViewProvider().getBaseLanguage() != HTMLLanguage.INSTANCE && HTMLLanguage.INSTANCE != element.getLanguage())
return true;
final PsiElement[] children = element.getChildren();
if (children.length > 0) {
if (children[0] instanceof XmlToken && XmlTokenType.XML_END_TAG_START == ((XmlToken) children[0]).getTokenType()) {
if (XmlErrorMessages.message("xml.parsing.closing.tag.matches.nothing").equals(element.getErrorDescription())) {
return false;
}
}
}
return true;
}
use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.
the class HtmlMissingClosingTagInspection method checkTag.
@Override
protected void checkTag(@NotNull XmlTag tag, @NotNull ProblemsHolder holder, boolean isOnTheFly) {
if (!(tag instanceof HtmlTag) || !XmlHighlightVisitor.shouldBeValidated(tag)) {
return;
}
final PsiElement child = tag.getLastChild();
if (child instanceof PsiErrorElement) {
return;
}
final XmlToken tagNameElement = XmlTagUtil.getStartTagNameElement(tag);
if (tagNameElement == null) {
return;
}
final String tagName = tagNameElement.getText();
if (HtmlUtil.isSingleHtmlTag(tagName) || XmlTagUtil.getEndTagNameElement(tag) != null) {
return;
}
holder.registerProblem(tagNameElement, XmlErrorMessages.message("element.missing.end.tag"), new MissingClosingTagFix(tagName));
}
use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.
the class RemoveExtraClosingTagIntentionAction method invoke.
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
final int offset = editor.getCaretModel().getOffset();
final PsiElement psiElement = file.findElementAt(offset);
if (psiElement == null || !psiElement.isValid() || !(psiElement instanceof XmlToken)) {
return;
}
doFix(psiElement);
}
Aggregations