avoid inserting duplicate colon when adding 'self' (PY-2652)

This commit is contained in:
Dmitry Jemerov
2011-01-14 19:34:46 +01:00
parent 2875c12c4f
commit 838a58f733
4 changed files with 15 additions and 2 deletions
@@ -14,7 +14,6 @@ import com.jetbrains.python.PyNames;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.PythonFileType;
import com.jetbrains.python.psi.PyFunction;
import com.jetbrains.python.psi.PyStringLiteralExpression;
import com.jetbrains.python.psi.PyUtil;
/**
@@ -55,7 +54,13 @@ public class PyMethodNameTypedHandler extends TypedHandlerDelegate {
else if (flags.isStaticMethod()) pname="";
documentManager.commitDocument(document);
// TODO: only print the ")" if Settings require it
EditorModificationUtil.typeInStringAtCaretHonorBlockSelection(editor, "("+pname+"):", true);
int caretOffset = editor.getCaretModel().getOffset();
String textToType = "(" + pname + ")";
CharSequence chars = editor.getDocument().getCharsSequence();
if (caretOffset == chars.length() || chars.charAt(caretOffset) != ':') {
textToType += ':';
}
EditorModificationUtil.typeInStringAtCaretHonorBlockSelection(editor, textToType, true);
editor.getCaretModel().moveToOffset(offset + 1 + pname.length()); // right after param name
return Result.STOP;
}
@@ -0,0 +1,2 @@
class C:
def someDefName(self):
@@ -0,0 +1,2 @@
class C:
def someDefName<caret>:
@@ -233,4 +233,8 @@ public class PyEditingTest extends PyLightFixtureTestCase {
public void testFirstParamStaticmethod() {
doTypingTest('(');
}
public void testFirstParamDuplicateColon() { // PY-2652
doTypingTest('(');
}
}