mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
WEB-13675 Do not insert redundant alignment between array elements and properties.
This alignment included in ChildAttributes for new properties and array elements leads to spaces being inserted instead of tabs inside indents for corresponding blocks when both SMART_TABS and USE_TAB_CHARACTER options are active. Test data for tests of line movements was updated because it made use of these alignments.
This commit is contained in:
@@ -48,8 +48,6 @@ public class JsonBlock implements ASTBlock {
|
||||
// lazy initialized on first call to #getSubBlocks()
|
||||
private List<Block> 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"<caret> }
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"foo": true,
|
||||
"bar": false,
|
||||
"baz"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"foo": true,
|
||||
"bar": false,<caret>
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
[
|
||||
1, <selection>[2], [true,
|
||||
false</selection>],
|
||||
1, <selection>[2],
|
||||
[
|
||||
true,
|
||||
false
|
||||
]</selection>,
|
||||
null
|
||||
]
|
||||
@@ -1,5 +1,8 @@
|
||||
[
|
||||
null,
|
||||
1, [2], [true,
|
||||
false]
|
||||
1, [2],
|
||||
[
|
||||
true,
|
||||
false
|
||||
]
|
||||
]
|
||||
@@ -1,6 +1,10 @@
|
||||
{
|
||||
"foo": <selection>false, "bar": 42,
|
||||
"baz": [1, 2,
|
||||
3</selection>],
|
||||
"foo": false,
|
||||
"bar": <selection>42,
|
||||
"baz": [
|
||||
1,
|
||||
2,
|
||||
3
|
||||
]</selection>,
|
||||
"quux": null
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
{
|
||||
"foo": false,
|
||||
"quux": null,
|
||||
"foo": false, "bar": 42,
|
||||
"baz": [1, 2,
|
||||
3]
|
||||
"bar": 42,
|
||||
"baz": [
|
||||
1,
|
||||
2,
|
||||
3
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user