+ if (withLeadingWhitespace) {
+ accumulatedTask = new ReformatWithHeadingWhitespaceTask(rangeMarker);
+ }
+ else {
+ accumulatedTask = new ReformatTask(rangeMarker);
+ }
+ }
+ // accumulatedTask is an instance of ReindentTask
+ else if (currentTask instanceof ReindentTask) {
+ // child indent is different from parent, the child condition
+ // accumulatedTask.getStartOffset() <= currentTask.getStartOffset()
+ // && accumulatedTask.getEndOffset() >= currentTask.getEndOffset()
+ // is always true here (ordered-by-end + up "if" in the method):
+
+ final CharSequence charsSequence = document.getCharsSequence();
+ int curEndOffset = currentTask.getEndOffset();
+ int curStartOffset = currentTask.getStartOffset();
+
+ // don't process ranges that have no new lines:
+ // optimization: the case is covered by formatting task, or does not need the indent (fragment-in-the-middle-of-line).
+ // compatibility: inline blocks have wrong indent due to historical reasons (always for inline function calls).
+ if (charsSequence.subSequence(curStartOffset, curEndOffset).toString().indexOf('\n') != -1) {
+ if (accumulatedTask.getEndOffset() > curEndOffset) {
+ // tail of parent indent (the order is from-end-to-start)
+ // restore "canonical" indent for calibration of the indent
+ freeFormattingActions.add(new ReformatWithHeadingWhitespaceTask(document.createRangeMarker(curEndOffset, curEndOffset)));
+
+ // add the indent,
+ // push indent task directly, that is in correct from-end-to-start order.
+ indentActions.add(new ReindentTask(
+ document.createRangeMarker(curEndOffset, accumulatedTask.getEndOffset()),
+ ((ReindentTask)accumulatedTask).getOldIndent()));