diff --git a/platform/lang-impl/src/com/intellij/formatting/AbstractBlockWrapper.java b/platform/lang-impl/src/com/intellij/formatting/AbstractBlockWrapper.java index aff90ee6e4fc..41fe998870de 100644 --- a/platform/lang-impl/src/com/intellij/formatting/AbstractBlockWrapper.java +++ b/platform/lang-impl/src/com/intellij/formatting/AbstractBlockWrapper.java @@ -341,6 +341,10 @@ public abstract class AbstractBlockWrapper { if (childIndent == null) childIndent = (IndentImpl)Indent.getContinuationWithoutFirstIndent(indentOption.USE_RELATIVE_INDENTS); IndentData indent = getIndent(indentOption, index, childIndent); + if (childIndent.isRelativeToDirectParent() && myParent != null) { + return new IndentData(indent.getIndentSpaces() + CoreFormatterUtil.getOffsetBefore(CoreFormatterUtil.getFirstLeaf(myParent)), + indent.getSpaces()); + } if (myParent == null || (myFlags & CAN_USE_FIRST_CHILD_INDENT_AS_BLOCK_INDENT) != 0 && getWhiteSpace().containsLineFeeds()) { return indent.add(getWhiteSpace()); } diff --git a/platform/lang-impl/src/com/intellij/formatting/CoreFormatterUtil.java b/platform/lang-impl/src/com/intellij/formatting/CoreFormatterUtil.java index dfef57ecf4d9..59e9b26561c5 100644 --- a/platform/lang-impl/src/com/intellij/formatting/CoreFormatterUtil.java +++ b/platform/lang-impl/src/com/intellij/formatting/CoreFormatterUtil.java @@ -250,6 +250,15 @@ public class CoreFormatterUtil { if (indent.getType() == Indent.Type.NONE) return new IndentData(0); if (indent.getType() == Indent.Type.SPACES) return new IndentData(0, indent.getSpaces()); return new IndentData(options.INDENT_SIZE); + } + @NotNull + public static LeafBlockWrapper getFirstLeaf(@NotNull AbstractBlockWrapper block) { + if (block instanceof LeafBlockWrapper) { + return (LeafBlockWrapper)block; + } + else { + return getFirstLeaf(((CompositeBlockWrapper)block).getChildren().get(0)); + } } }