// if not already correctly indented
if (!newLineAndIndent.equals(whitespaceRun)) {
if (getFormattingPreferences().getClearAllBlankLines()) {
if (whitespaceRun != null) {
// replace existing whitespace run
indentation = new ReplaceEdit(indentStartOffset, whitespaceRun.length(), newLineAndIndent);
}
else {
// just insert correct indent
indentation = new InsertEdit(indentStartOffset, newLineAndIndent);
}
}
// Keep the empty lines
else {
// just insert correct indent
if(whitespaceRun == null)
indentation = new InsertEdit(indentStartOffset, newLineAndIndent);
// Need to preserve the number of empty lines, but still indent on the current line properly
else {
String existingDelimiters = extractLineDelimiters(whitespaceRun, currentRegion);
if(existingDelimiters != null && existingDelimiters.length() > 0) {
String formatted = existingDelimiters + indentString;
// Don't perform a replace if the formatted string is the same as the existing whitespaceRun
if(!formatted.equals(whitespaceRun))
indentation = new ReplaceEdit(indentStartOffset, whitespaceRun.length(), formatted);
}
// No blank lines to preserve - correct the indent
else
indentation = new ReplaceEdit(indentStartOffset, whitespaceRun.length(), newLineAndIndent);
}
}
}
if(indentation != null)