From 94b4fad389354a2ef070cbb3d4af4dfaa397ca4f Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Wed, 23 Jan 2013 11:41:41 +0400 Subject: [PATCH] WEB-5568 Expand CoffeeScript Formatter Options to Match Other Languages Respect 'relative to parent' indent flag during child code style attributes processing --- .../com/intellij/formatting/AbstractBlockWrapper.java | 4 ++++ .../src/com/intellij/formatting/CoreFormatterUtil.java | 9 +++++++++ 2 files changed, 13 insertions(+) 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)); + } } }