diff --git a/json/src/com/intellij/json/formatter/JsonBlock.java b/json/src/com/intellij/json/formatter/JsonBlock.java index 2dccd347e177..8ffff7f2dc44 100644 --- a/json/src/com/intellij/json/formatter/JsonBlock.java +++ b/json/src/com/intellij/json/formatter/JsonBlock.java @@ -48,8 +48,6 @@ public class JsonBlock implements ASTBlock { // lazy initialized on first call to #getSubBlocks() private List mySubBlocks = null; - private final Alignment myChildAlignment = Alignment.createAlignment(); - private final Alignment myPropertyValueAlignment; private final Wrap myChildWrap; @@ -119,9 +117,8 @@ public class JsonBlock implements ASTBlock { JsonCodeStyleSettings customSettings = getCustomSettings(); if (isContainer() && childNodeType != JsonElementTypes.COMMA && !BRACES.contains(childNodeType)) { - assert myChildWrap != null && myChildAlignment != null; + assert myChildWrap != null; wrap = myChildWrap; - alignment = myChildAlignment; indent = Indent.getNormalIndent(); } // Handle properties alignment @@ -184,7 +181,10 @@ public class JsonBlock implements ASTBlock { @Override public ChildAttributes getChildAttributes(int newChildIndex) { if (isContainer()) { - return new ChildAttributes(Indent.getNormalIndent(), myChildAlignment); + // WEB-13675: For some reason including alignment in child attributes causes + // indents to consist solely of spaces when both USE_TABS and SMART_TAB + // options are enabled. + return new ChildAttributes(Indent.getNormalIndent(), null); } // Will use continuation indent for cases like { "foo" } return new ChildAttributes(null, null); @@ -192,8 +192,8 @@ public class JsonBlock implements ASTBlock { @Override public boolean isIncomplete() { - IElementType nodeType = myNode.getElementType(); - ASTNode lastChildNode = myNode.getLastChildNode(); + final IElementType nodeType = myNode.getElementType(); + final ASTNode lastChildNode = myNode.getLastChildNode(); if (nodeType == JsonElementTypes.OBJECT) { return lastChildNode != null && lastChildNode.getElementType() != JsonElementTypes.R_CURLY; } diff --git a/json/tests/test/com/intellij/json/JsonEditingTest.java b/json/tests/test/com/intellij/json/JsonEditingTest.java index bb6f5088c89c..42421979f490 100644 --- a/json/tests/test/com/intellij/json/JsonEditingTest.java +++ b/json/tests/test/com/intellij/json/JsonEditingTest.java @@ -3,6 +3,9 @@ package com.intellij.json; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.util.Computable; import com.intellij.psi.PsiFile; +import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; import org.jetbrains.annotations.NotNull; /** @@ -37,4 +40,22 @@ public class JsonEditingTest extends JsonTestCase { public void testNormalIndentAfterPropertyWithoutComma() { doTest("\n"); } + + // WEB-13675 + public void testIndentWithTabsWhenSmartTabEnabled() { + CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(myFixture.getProject()); + CommonCodeStyleSettings.IndentOptions indentOptions = settings.getCommonSettings(JsonLanguage.INSTANCE).getIndentOptions(); + assertNotNull(indentOptions); + CommonCodeStyleSettings.IndentOptions oldSettings = (CommonCodeStyleSettings.IndentOptions)indentOptions.clone(); + indentOptions.TAB_SIZE = 4; + indentOptions.INDENT_SIZE = 4; + indentOptions.USE_TAB_CHARACTER = true; + indentOptions.SMART_TABS = true; + try { + doTest("\n\"baz\""); + } + finally { + indentOptions.copyFrom(oldSettings); + } + } } diff --git a/json/tests/testData/editing/IndentWithTabsWhenSmartTabEnabled.after.json b/json/tests/testData/editing/IndentWithTabsWhenSmartTabEnabled.after.json new file mode 100644 index 000000000000..152513cad497 --- /dev/null +++ b/json/tests/testData/editing/IndentWithTabsWhenSmartTabEnabled.after.json @@ -0,0 +1,5 @@ +{ + "foo": true, + "bar": false, + "baz" +} \ No newline at end of file diff --git a/json/tests/testData/editing/IndentWithTabsWhenSmartTabEnabled.json b/json/tests/testData/editing/IndentWithTabsWhenSmartTabEnabled.json new file mode 100644 index 000000000000..69824365e9e8 --- /dev/null +++ b/json/tests/testData/editing/IndentWithTabsWhenSmartTabEnabled.json @@ -0,0 +1,4 @@ +{ + "foo": true, + "bar": false, +} \ No newline at end of file diff --git a/json/tests/testData/mover/ArraySelectionMovedDown.json b/json/tests/testData/mover/ArraySelectionMovedDown.json index 476b56d42dea..81e4dc2bcd0e 100644 --- a/json/tests/testData/mover/ArraySelectionMovedDown.json +++ b/json/tests/testData/mover/ArraySelectionMovedDown.json @@ -1,5 +1,8 @@ [ - 1, [2], [true, - false], + 1, [2], + [ + true, + false + ], null ] \ No newline at end of file diff --git a/json/tests/testData/mover/ArraySelectionMovedDown_afterDown.json b/json/tests/testData/mover/ArraySelectionMovedDown_afterDown.json index 9db514b06905..1a7a49635d95 100644 --- a/json/tests/testData/mover/ArraySelectionMovedDown_afterDown.json +++ b/json/tests/testData/mover/ArraySelectionMovedDown_afterDown.json @@ -1,5 +1,8 @@ [ null, - 1, [2], [true, - false] + 1, [2], + [ + true, + false + ] ] \ No newline at end of file diff --git a/json/tests/testData/mover/ObjectSelectionMovedDown.json b/json/tests/testData/mover/ObjectSelectionMovedDown.json index 57efbe402072..ed363c1d3d6f 100644 --- a/json/tests/testData/mover/ObjectSelectionMovedDown.json +++ b/json/tests/testData/mover/ObjectSelectionMovedDown.json @@ -1,6 +1,10 @@ { - "foo": false, "bar": 42, - "baz": [1, 2, - 3], + "foo": false, + "bar": 42, + "baz": [ + 1, + 2, + 3 + ], "quux": null } \ No newline at end of file diff --git a/json/tests/testData/mover/ObjectSelectionMovedDown_afterDown.json b/json/tests/testData/mover/ObjectSelectionMovedDown_afterDown.json index 860d3b5d3783..ebf686822340 100644 --- a/json/tests/testData/mover/ObjectSelectionMovedDown_afterDown.json +++ b/json/tests/testData/mover/ObjectSelectionMovedDown_afterDown.json @@ -1,6 +1,10 @@ { + "foo": false, "quux": null, - "foo": false, "bar": 42, - "baz": [1, 2, - 3] + "bar": 42, + "baz": [ + 1, + 2, + 3 + ] } \ No newline at end of file