}
}
else if (TEXT.equals(selectionStrategy)) {
// underline the text between the tags
if (node.getNodeType() == Node.TEXT_NODE) {
IDOMText textNode = (IDOMText) node;
int start = textNode.getStartOffset();
String value = textNode.getNodeValue();
int index = 0;
char curChar = value.charAt(index);
// here we are finding start offset by skipping over
// whitespace:
while ((curChar == '\n') || (curChar == '\t') || (curChar == '\r') || (curChar == ' ')) {
curChar = value.charAt(index);
index++;
}
if (index > 0) {
index--;
}
start = start + index;
startEndPositions[0] = start;
startEndPositions[1] = start + value.trim().length();
}
else if (node.getNodeType() == Node.ELEMENT_NODE) {
IDOMElement element = (IDOMElement) node;
Node child = element.getFirstChild();
if (child instanceof IDOMNode) {
IDOMNode xmlChild = ((IDOMNode) child);
startEndPositions[0] = xmlChild.getStartOffset();
startEndPositions[1] = xmlChild.getEndOffset();
}
}
}
else if (FIRST_NON_WHITESPACE_TEXT.equals(selectionStrategy)) {
// search through all child nodes and return range of
// first non-whitespace
// text node
if (node.getNodeType() == Node.ELEMENT_NODE) {
NodeList nodes = node.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node currentNode = nodes.item(i);
if (currentNode.getNodeType() == Node.TEXT_NODE) {
// TODO (Trung) I don't think we should call
// getNodeValue(), trim(), length()
// repeatedly.
// This is inefficient, to improve use local
// variables to store values.
IDOMText textNode = (IDOMText) currentNode;
if (textNode.getNodeValue().trim().length() > 0) {
String value = textNode.getNodeValue();
int index = 0;
int start = textNode.getStartOffset();
char curChar = value.charAt(index);
// here we are finding start offset by
// skipping over whitespace:
while ((curChar == '\n') || (curChar == '\t') || (curChar == '\r') || (curChar == ' ')) {
curChar = value.charAt(index);