* @param parentConstraints
* @param currentDOMRegion
* @param previousRegion
*/
private void formatContent(TextEdit textEdit, Position formatRange, XMLFormattingConstraints parentConstraints, DOMRegion currentDOMRegion, IStructuredDocumentRegion previousRegion) {
IStructuredDocumentRegion currentRegion = currentDOMRegion.documentRegion;
String fullText = currentDOMRegion.domNode.getSource();
// check if in preserve space mode, if so, don't touch anything but
// make sure to update available line width
String whitespaceMode = parentConstraints.getWhitespaceStrategy();
if (XMLFormattingConstraints.PRESERVE.equals(whitespaceMode)) {
int availableLineWidth = parentConstraints.getAvailableLineWidth();
availableLineWidth = updateLineWidthWithLastLine(fullText, availableLineWidth);
// update available line width in constraints
parentConstraints.setAvailableLineWidth(availableLineWidth);
// A text node can contain multiple structured document regions - sync the documentRegion
// with the last region of the node since the text from all regions was formatted
currentDOMRegion.documentRegion = currentDOMRegion.domNode.getLastStructuredDocumentRegion();
return;
}
// if content is just whitespace and there's something after it
// just skip over this region because region will take care of it
boolean isAllWhitespace = ((IDOMText) currentDOMRegion.domNode).isElementContentWhitespace();
IStructuredDocumentRegion nextDocumentRegion = null;
if (isAllWhitespace) {
parentConstraints.setAvailableLineWidth(fPreferences.getMaxLineWidth());
nextDocumentRegion = currentRegion.getNext();
if (nextDocumentRegion != null)
return;
}
// special handling if text follows an entity or cdata region
if (!XMLFormattingConstraints.COLLAPSE.equals(whitespaceMode) && previousRegion != null) {
String previouRegionType = previousRegion.getType();
if (DOMRegionContext.XML_ENTITY_REFERENCE.equals(previouRegionType) || DOMRegionContext.XML_CDATA_TEXT.equals(previouRegionType))
whitespaceMode = XMLFormattingConstraints.COLLAPSE;
}
// also, special handling if text is before an entity or cdata region
if (!XMLFormattingConstraints.COLLAPSE.equals(whitespaceMode)) {
// get next document region if dont already have it
if (nextDocumentRegion == null)
nextDocumentRegion = currentRegion.getNext();
if (nextDocumentRegion != null) {
String nextRegionType = nextDocumentRegion.getType();
if (DOMRegionContext.XML_ENTITY_REFERENCE.equals(nextRegionType) || DOMRegionContext.XML_CDATA_TEXT.equals(nextRegionType))
whitespaceMode = XMLFormattingConstraints.COLLAPSE;
}
}
final IStructuredDocumentRegion lastRegion = currentDOMRegion.domNode.getLastStructuredDocumentRegion();
formatTextInContent(textEdit, parentConstraints, currentRegion, lastRegion != null ? lastRegion.getNext(): null, fullText, whitespaceMode);
// A text node can contain multiple structured document regions - sync the documentRegion
// with the last region of the node since the text from all regions was formatted
currentDOMRegion.documentRegion = lastRegion;
}