mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix alignment when pressing Enter in list literal (PY-2407); thankfully the logic for calculating whether a child needs alignment can be much cleaner now
This commit is contained in:
@@ -209,13 +209,8 @@ public class PyBlock implements ASTBlock {
|
||||
return false;
|
||||
}
|
||||
if (PyTokenTypes.CLOSE_BRACES.contains(childType)) {
|
||||
PsiElement psi = child.getPsi();
|
||||
PyArgumentList argumentList = PsiTreeUtil.getParentOfType(psi, PyArgumentList.class);
|
||||
if (argumentList != null) {
|
||||
if (psi != null && psi.getParent() == argumentList &&
|
||||
(child.getElementType() == PyTokenTypes.RPAR || argumentList.getArguments().length == 1)) {
|
||||
return false;
|
||||
}
|
||||
ASTNode prevNonSpace = findPrevNonSpaceNode(child);
|
||||
if (prevNonSpace != null && prevNonSpace.getElementType() == PyTokenTypes.COMMA) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -227,6 +222,14 @@ public class PyBlock implements ASTBlock {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ASTNode findPrevNonSpaceNode(ASTNode node) {
|
||||
do {
|
||||
node = node.getTreePrev();
|
||||
} while(node != null && (node.getElementType() == TokenType.WHITE_SPACE || PyTokenTypes.WHITESPACE.contains(node.getElementType())));
|
||||
return node;
|
||||
}
|
||||
|
||||
private static boolean hasLineBreaksBefore(ASTNode child, int minCount) {
|
||||
return isWhitespaceWithLineBreaks(TreeUtil.findLastLeaf(child.getTreePrev()), minCount) ||
|
||||
isWhitespaceWithLineBreaks(child.getFirstChildNode(), minCount);
|
||||
|
||||
@@ -71,6 +71,16 @@ public class PyIndentTest extends PyLightFixtureTestCase {
|
||||
doTest("__all__ = [a for<caret>", "__all__ = [a for\n" + " <caret>");
|
||||
}
|
||||
|
||||
public void testAlignInListOnceMore() { // PY-2407
|
||||
doTest("for id in [\"SEARCH_RESULT_ATTRIBUTES\", \n" +
|
||||
" \"WRITE_SEARCH_RESULT_ATTRIBUTES\", \n" +
|
||||
" \"IDENTIFIER_UNDER_CARET_ATTRIBUTES\",<caret>]:",
|
||||
"for id in [\"SEARCH_RESULT_ATTRIBUTES\", \n" +
|
||||
" \"WRITE_SEARCH_RESULT_ATTRIBUTES\", \n" +
|
||||
" \"IDENTIFIER_UNDER_CARET_ATTRIBUTES\",\n" +
|
||||
" <caret>]:");
|
||||
}
|
||||
|
||||
public void testAlignInDict() {
|
||||
doTest("some_call({'aaa': 'v1',<caret>})",
|
||||
"some_call({'aaa': 'v1',\n" +
|
||||
|
||||
Reference in New Issue
Block a user