use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class DtdSelectioner method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
PsiElement[] children = e.getChildren();
PsiElement first = null;
PsiElement last = null;
for (PsiElement child : children) {
if (child instanceof XmlToken) {
XmlToken token = (XmlToken) child;
if (token.getTokenType() == XmlTokenType.XML_TAG_END) {
last = token;
break;
}
if (token.getTokenType() == XmlTokenType.XML_ELEMENT_DECL_START || token.getTokenType() == XmlTokenType.XML_ATTLIST_DECL_START) {
first = token;
}
}
}
List<TextRange> result = new ArrayList<>(1);
if (first != null && last != null) {
final int offset = last.getTextRange().getEndOffset() + 1;
result.addAll(ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, new TextRange(first.getTextRange().getStartOffset(), offset < editorText.length() ? offset : editorText.length()), false));
}
return result;
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class HtmlSelectioner method getMinimalTextRangeLength.
@Override
public int getMinimalTextRangeLength(@NotNull PsiElement element, @NotNull CharSequence text, int cursorOffset) {
if (WebEditorOptions.getInstance().isSelectWholeCssIdentifierOnDoubleClick()) {
final XmlAttribute attribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class);
final XmlAttributeValue attributeValue = PsiTreeUtil.getParentOfType(element, XmlAttributeValue.class);
if (attribute != null && attributeValue != null) {
if (HtmlUtil.CLASS_ATTRIBUTE_NAME.equalsIgnoreCase(attribute.getName())) {
final TextRange valueTextRange = attributeValue.getValueTextRange();
if (!valueTextRange.isEmpty()) {
int start = cursorOffset;
int end = cursorOffset;
while (start > valueTextRange.getStartOffset()) {
if (!JAVA_IDENTIFIER_AND_HYPHEN_CONDITION.value(text.charAt(start - 1))) {
break;
}
start--;
}
while (end < valueTextRange.getEndOffset()) {
if (!JAVA_IDENTIFIER_AND_HYPHEN_CONDITION.value(text.charAt(end + 1))) {
break;
}
end++;
}
return end - start;
}
}
}
}
return super.getMinimalTextRangeLength(element, text, cursorOffset);
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class HtmlSelectioner method select.
@Override
public List<TextRange> select(PsiElement e, @NotNull CharSequence editorText, int cursorOffset, @NotNull Editor editor) {
List<TextRange> result;
if (!(e instanceof XmlToken) || XmlTokenSelectioner.shouldSelectToken((XmlToken) e) || ((XmlToken) e).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) {
result = super.select(e, editorText, cursorOffset, editor);
} else {
result = ContainerUtil.newArrayList();
}
final PsiElement parent = e.getParent();
if (parent instanceof XmlComment) {
result.addAll(expandToWholeLine(editorText, parent.getTextRange(), true));
}
PsiFile psiFile = e.getContainingFile();
addAttributeSelection(result, editor, cursorOffset, editorText, e);
final FileViewProvider fileViewProvider = psiFile.getViewProvider();
for (Language lang : fileViewProvider.getLanguages()) {
final PsiFile langFile = fileViewProvider.getPsi(lang);
if (langFile != psiFile)
addAttributeSelection(result, editor, cursorOffset, editorText, fileViewProvider.findElementAt(cursorOffset, lang));
}
EditorHighlighter highlighter = HighlighterFactory.createHighlighter(e.getProject(), psiFile.getVirtualFile());
highlighter.setText(editorText);
addTagSelection2(e, result);
return result;
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class HtmlSelectioner method addAttributeSelection.
private static void addAttributeSelection(@NotNull List<TextRange> result, @NotNull Editor editor, int cursorOffset, @NotNull CharSequence editorText, @Nullable PsiElement e) {
final XmlAttribute attribute = PsiTreeUtil.getParentOfType(e, XmlAttribute.class);
if (attribute != null) {
result.add(attribute.getTextRange());
final XmlAttributeValue value = attribute.getValueElement();
if (value != null) {
if (HtmlUtil.CLASS_ATTRIBUTE_NAME.equalsIgnoreCase(attribute.getName())) {
addClassAttributeRanges(result, editor, cursorOffset, editorText, value);
}
final TextRange range = value.getTextRange();
result.add(range);
if (value.getFirstChild() != null && value.getFirstChild().getNode().getElementType() == XmlTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER) {
result.add(new TextRange(range.getStartOffset() + 1, range.getEndOffset() - 1));
}
}
}
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class XmlEncodingReferenceProvider method extractFromContentAttribute.
public static PsiReference[] extractFromContentAttribute(final XmlAttributeValue value) {
String text = value.getValue();
int start = text.indexOf(CHARSET_PREFIX);
if (start != -1) {
start += CHARSET_PREFIX.length();
int end = text.indexOf(';', start);
if (end == -1)
end = text.length();
String charsetName = text.substring(start, end);
TextRange textRange = new TextRange(start, end).shiftRight(xmlAttributeValueRange(value).getStartOffset());
return new PsiReference[] { new XmlEncodingReference(value, charsetName, textRange, 0) };
}
return PsiReference.EMPTY_ARRAY;
}
Aggregations