mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-891 Ctrl + Shift +Enter doesn't move to next line in case of method definition
This commit is contained in:
+2
@@ -14,6 +14,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.jetbrains.python.codeInsight.editorActions.smartEnter.enterProcessors.EnterProcessor;
|
||||
import com.jetbrains.python.codeInsight.editorActions.smartEnter.enterProcessors.PyCommentBreakerEnterProcessor;
|
||||
import com.jetbrains.python.codeInsight.editorActions.smartEnter.enterProcessors.PyPlainEnterProcessor;
|
||||
import com.jetbrains.python.codeInsight.editorActions.smartEnter.fixers.*;
|
||||
import com.jetbrains.python.psi.PyFile;
|
||||
import com.jetbrains.python.psi.PyStatement;
|
||||
@@ -49,6 +50,7 @@ public class PySmartEnterProcessor extends SmartEnterProcessor {
|
||||
ourFixers.add(new PyClassFixer());
|
||||
|
||||
ourProcessors.add(new PyCommentBreakerEnterProcessor());
|
||||
ourProcessors.add(new PyPlainEnterProcessor());
|
||||
}
|
||||
|
||||
private static class TooManyAttemptsException extends Exception {
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.jetbrains.python.codeInsight.editorActions.smartEnter.enterProcessors;
|
||||
|
||||
import com.intellij.openapi.editor.CaretModel;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.jetbrains.python.codeInsight.editorActions.smartEnter.SmartEnterUtil;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import com.jetbrains.python.psi.PyStatementList;
|
||||
import com.jetbrains.python.psi.PyStatementPart;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* Author: Alexey.Ivanov
|
||||
* Date: 28.04.2010
|
||||
* Time: 19:15:58
|
||||
*/
|
||||
public class PyPlainEnterProcessor implements EnterProcessor {
|
||||
@Nullable
|
||||
private static PyStatementList getStatementList(PsiElement psiElement, Editor editor) {
|
||||
if (psiElement instanceof PyStatementPart) {
|
||||
return ((PyStatementPart)psiElement).getStatementList();
|
||||
}
|
||||
else if (psiElement instanceof PyFunction) {
|
||||
return ((PyFunction)psiElement).getStatementList();
|
||||
}
|
||||
else if (psiElement instanceof PyClass) {
|
||||
return ((PyClass)psiElement).getStatementList();
|
||||
} else {
|
||||
final CaretModel caretModel = editor.getCaretModel();
|
||||
final PsiElement atCaret = psiElement.getContainingFile().findElementAt(caretModel.getOffset());
|
||||
PyStatementPart statementPart = PsiTreeUtil.getParentOfType(atCaret, PyStatementPart.class);
|
||||
if (statementPart != null) {
|
||||
return statementPart.getStatementList();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean doEnter(Editor editor, PsiElement psiElement, boolean isModified) {
|
||||
PyStatementList statementList = getStatementList(psiElement, editor);
|
||||
if (statementList != null && statementList.getStatements().length == 0) {
|
||||
SmartEnterUtil.plainEnter(editor);
|
||||
//editor.getCaretModel().moveToOffset(statementList.getTextRange().getEndOffset());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -18,16 +18,18 @@ import com.jetbrains.python.psi.PyUtil;
|
||||
* Time: 18:41:08
|
||||
*/
|
||||
public class PyClassFixer implements PyFixer {
|
||||
// TODO: 'class' -> 'class :'
|
||||
public void apply(Editor editor, PySmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
|
||||
if (psiElement instanceof PyClass) {
|
||||
final PsiElement colon = PyUtil.getChildByFilter(psiElement, TokenSet.create(PyTokenTypes.COLON), 0);
|
||||
if (colon == null) {
|
||||
final PyClass aClass = (PyClass)psiElement;
|
||||
|
||||
final PyArgumentList argList = PsiTreeUtil.getChildOfType(aClass, PyArgumentList.class);
|
||||
int offset = argList.getTextRange().getEndOffset();
|
||||
String textToInsert = ":";
|
||||
if (aClass.getNameNode() == null) {
|
||||
processor.registerUnresolvedError(argList.getTextRange().getEndOffset() + 1);
|
||||
textToInsert = " :";
|
||||
}
|
||||
editor.getDocument().insertString(offset, textToInsert);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-4
@@ -25,17 +25,14 @@ public class PyExceptFixer implements PyFixer {
|
||||
int offset = PyUtil.getChildByFilter(exceptPart,
|
||||
TokenSet.create(PyTokenTypes.EXCEPT_KEYWORD), 0).getTextRange().getEndOffset();
|
||||
final PyExpression exceptClass = exceptPart.getExceptClass();
|
||||
String text = " :";
|
||||
if (exceptClass != null) {
|
||||
offset = exceptClass.getTextRange().getEndOffset();
|
||||
text = ":";
|
||||
}
|
||||
final PyExpression target = exceptPart.getTarget();
|
||||
if (target != null) {
|
||||
offset = target.getTextRange().getEndOffset();
|
||||
text = ":";
|
||||
}
|
||||
editor.getDocument().insertString(offset, text);
|
||||
editor.getDocument().insertString(offset, ":");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
class Foo:
|
||||
def __init__(self)<caret>
|
||||
@@ -0,0 +1,3 @@
|
||||
class Foo:
|
||||
def __init__(self):
|
||||
<caret>
|
||||
@@ -1 +1,2 @@
|
||||
while a:<caret>
|
||||
while a:
|
||||
<caret>
|
||||
@@ -95,4 +95,8 @@ public class PySmartEnterTest extends PyLightFixtureTestCase {
|
||||
public void testComment() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPy891() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user