* parameter was <code>DELETE_CONTENTS</code>, the
* return value is null.
*/
private DocumentFragment traverseSameContainer( int how )
{
DocumentFragment frag = null;
if (how != DELETE_CONTENTS) {
frag = fDocument.createDocumentFragment();
}
// If selection is empty, just return the fragment
if (fStartOffset == fEndOffset) {
return frag;
}
// Text, CDATASection, Comment and ProcessingInstruction nodes need special case handling
final short nodeType = fStartContainer.getNodeType();
if (nodeType == Node.TEXT_NODE ||
nodeType == Node.CDATA_SECTION_NODE ||
nodeType == Node.COMMENT_NODE ||
nodeType == Node.PROCESSING_INSTRUCTION_NODE) {
// get the substring
String s = fStartContainer.getNodeValue();
String sub = s.substring(fStartOffset, fEndOffset);
// set the original text node to its new value
if (how != CLONE_CONTENTS) {
((CharacterDataImpl)fStartContainer).deleteData(fStartOffset,
fEndOffset-fStartOffset);
// Nothing is partially selected, so collapse to start point
collapse(true);
}
if (how == DELETE_CONTENTS) {
return null;
}
if (nodeType == Node.TEXT_NODE) {
frag.appendChild(fDocument.createTextNode(sub));
}
else if (nodeType == Node.CDATA_SECTION_NODE) {
frag.appendChild(fDocument.createCDATASection(sub));
}
else if (nodeType == Node.COMMENT_NODE) {
frag.appendChild(fDocument.createComment(sub));
}
else { // nodeType == Node.PROCESSING_INSTRUCTION_NODE
frag.appendChild(fDocument.createProcessingInstruction(fStartContainer.getNodeName(), sub));
}
return frag;
}
// Copy nodes between the start/end offsets.
Node n = getSelectedNode( fStartContainer, fStartOffset );
int cnt = fEndOffset - fStartOffset;
while( cnt > 0 ) {
Node sibling = n.getNextSibling();
Node xferNode = traverseFullySelected( n, how );
if ( frag!=null )
frag.appendChild( xferNode );
--cnt;
n = sibling;
}
// Nothing is partially selected, so collapse to start point