IDEA-192807 Enter calculates wrong indent

GitOrigin-RevId: ee6543a8e89f9a49e6303f78e86cd343ee78220f
This commit is contained in:
Rustam Vishnyakov
2021-01-18 10:17:35 +00:00
committed by intellij-monorepo-bot
parent f204c6e6a8
commit 328c05d165
2 changed files with 29 additions and 1 deletions
@@ -613,4 +613,21 @@ public class JavaEnterActionTest extends AbstractEnterActionTestCase {
"}"
);
}
public void testIdea192807() {
doTextTest(
"java",
"class MyTest\n" +
"{\n" +
" private void foo() { String a = \"a\";<caret> String b = \"b\";}\n" +
"}",
"class MyTest\n" +
"{\n" +
" private void foo() { String a = \"a\";\n" +
" <caret>String b = \"b\";}\n" +
"}"
);
}
}
@@ -136,7 +136,7 @@ public abstract class JavaLikeLangLineIndentProvider implements LineIndentProvid
}
int statementStart = getStatementStartOffset(beforeSemicolon, dropIndentAfterReturnLike(beforeSemicolon));
SemanticEditorPosition atStatementStart = getPosition(editor, statementStart);
if (atStatementStart.isAt(BlockOpeningBrace)) {
if (isAtBlockOpeningOnSameLine(atStatementStart)) {
return myFactory.createIndentCalculator(getIndentInBlock(project, language, atStatementStart), this::getDeepBlockStatementStartOffset);
}
if (!isInsideForLikeConstruction(atStatementStart)) {
@@ -203,6 +203,17 @@ public abstract class JavaLikeLangLineIndentProvider implements LineIndentProvid
return null;
}
private static boolean isAtBlockOpeningOnSameLine(@NotNull SemanticEditorPosition position) {
SemanticEditorPosition pos = position.copy();
while (!pos.isAt(BlockOpeningBrace)) {
pos.moveBefore();
if (pos.isAtEnd() || pos.isAtMultiline()) {
return false;
}
}
return true;
}
private SemanticEditorPosition afterOptionalWhitespaceOnSameLine(@NotNull Editor editor, int offset) {
SemanticEditorPosition position = getPosition(editor, offset);
if (position.isAt(Whitespace)) {