IDEA-142439 Wrong cursor placement when creating a class after brackets autocomplete

This commit is contained in:
peter
2015-07-09 20:49:00 +02:00
parent 4ff9ba80f3
commit 4f6e27823e
5 changed files with 22 additions and 3 deletions
@@ -309,7 +309,11 @@ public class JavaSmartEnterProcessor extends SmartEnterProcessor {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(file.getProject());
final boolean old = settings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE;
settings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = false;
PsiElement elt = PsiTreeUtil.getParentOfType(file.findElementAt(caretOffset - 1), PsiCodeBlock.class);
PsiElement leaf = file.findElementAt(caretOffset - 1);
PsiElement elt = PsiTreeUtil.getParentOfType(leaf, PsiCodeBlock.class);
if (elt == null && leaf != null && leaf.getParent() instanceof PsiClass) {
elt = leaf.getParent();
}
reformat(elt);
settings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = old;
editor.getCaretModel().moveToOffset(caretOffset - 1);
@@ -17,7 +17,7 @@ public class MissingClassBodyFixer implements Fixer {
if (psiClass.getLBrace() == null) {
int offset = psiClass.getTextRange().getEndOffset();
editor.getDocument().insertString(offset, " {\n}");
editor.getDocument().insertString(offset, "{\n}");
editor.getCaretModel().moveToOffset(offset);
}
}
@@ -0,0 +1,4 @@
class Test
{
class Foo<caret>
}
@@ -0,0 +1,7 @@
class Test
{
class Foo
{
<caret>
}
}
@@ -232,7 +232,11 @@ public class CompleteStatementTest extends EditorActionTestCase {
public void testIDEA25139() throws Exception {
doTestBracesNextLineStyle();
}
public void testClassBracesNextLine() throws Exception {
doTestBracesNextLineStyle();
}
public void testBeforeIfRBrace() throws Exception {
CodeStyleSettingsManager.getSettings(getProject()).KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true;
doTest();