new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(editor.getProject(), editor);
}
private TextRange getRangeFromToken(XmlTokenImpl token, CaretModel caretModel, String direction){
XmlAttributeImpl attribute = getAttributeFromToken(token);
if (RIGHT.equals(direction)){
//account for namespace
if (token.getTokenType() == XmlTokenType.XML_NAME){
//special case for namespace
if (attribute.isNamespaceDeclaration()){
String namespacePrefix = attribute.getNamespacePrefix();
String localName = attribute.getLocalName();
int textOffset = attribute.getFirstChild().getTextOffset();
int localNameOffset = textOffset + namespacePrefix.length() + 1;
//the caret is on the prefix, so go to the local name
if (caretModel.getOffset() < localNameOffset){
return new TextRange(localNameOffset, localNameOffset + localName.length());
}
PsiElement attributeValue = attribute.getLastChild().getChildren()[1];
return attributeValue.getTextRange();
}
//just a plain attribute (not a namespace)
else{
//the caret is either on the namespace or it's not a namespace, so go to the value
PsiElement attributeValue = attribute.getLastChild();
PsiElement valueToken = attributeValue.getChildren()[1];
return valueToken.getTextRange();
}
}
//the caret is on the attribute value
else if (token.getTokenType() == XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN){
//Don't forget the whitespace!
PsiElement whiteSpace = attribute.getNextSibling();
attribute = (XmlAttributeImpl) whiteSpace.getNextSibling();
//you've moved to the attribute name of the next attribute
if (attribute.isNamespaceDeclaration()){
String namespacePrefix = attribute.getNamespacePrefix();
int textOffset = attribute.getFirstChild().getTextOffset();
int localNameOffset = textOffset + namespacePrefix.length() + 1;
//time to select the prefix
if (caretModel.getOffset() < localNameOffset){
return new TextRange(textOffset, textOffset + namespacePrefix.length());
}
}
//just return the attribute name
return attribute.getFirstChild().getTextRange();
}
}
else if (LEFT.equals(direction)){
//special case for namespace
if (attribute.isNamespaceDeclaration()){
String namespacePrefix = attribute.getNamespacePrefix();
String localName = attribute.getLocalName();
int textOffset = attribute.getFirstChild().getTextOffset();
int localNameOffset = textOffset + namespacePrefix.length() + 1;
//the caret is on the prefix, so go to the local name
if (caretModel.getOffset() < localNameOffset){
return new TextRange(localNameOffset, localNameOffset + localName.length());