if (range == null || range.isEmpty()) {
return null;
}
boolean ordered = range.isOrdered();
IDOMPosition start = ordered ? range.getStartPosition() : range
.getEndPosition();
IDOMPosition end = ordered ? range.getEndPosition() : range
.getStartPosition();
Node startContainer = start.getContainerNode();
Node endContainer = end.getContainerNode();
Node common = DOMUtil.findCommonAncester(start.getContainerNode(), end
.getContainerNode());
if (common == null) {
// should not happen.
return null;
}
if (common instanceof Text) {
// under the same Text scope
range = doTextNodeStyleApply((Text) common, start.getOffset(), end
.getOffset());
return range;
}
if (startContainer instanceof Text) {
// if the start offset is 0,then skip split the Text
if (start.getOffset() > 0) {
startContainer = ((Text) startContainer).splitText(start
.getOffset());
start = new DOMRefPosition(startContainer, false);
}
} else {
startContainer = start.getNextSiblingNode();
}
if (endContainer instanceof Text) {
if (end.getOffset() > 0) {
endContainer = ((Text) endContainer).splitText(end
.getOffset());
endContainer = endContainer.getPreviousSibling();
} else {
endContainer = endContainer.getPreviousSibling();
}
} else {
endContainer = end.getPreviousSiblingNode();
}
for (Node node = startContainer; node != endContainer; node = EditModelQuery
.getInstance().getNextLeafNeighbor(node)) {
if (EditModelQuery.hasAncestor(node, getTag(), true)) {