int docSize = editor.getDocument().size();
if (cursorLoc != -1) {
// Insert the attachment at the cursor location.
CMutableDocument doc = editor.getDocument();
Point<ContentNode> point = doc.locate(cursorLoc);
doc.insertXml(point, xml);
} else {
LineContainers.appendLine(editor.getDocument(), xml);
}
// Calculate the link length for the attachment.
to = cursorLoc + editor.getDocument().size() - docSize;