diff --git a/python/src/com/jetbrains/python/codeInsight/PySmartKeysOptions.java b/python/src/com/jetbrains/python/codeInsight/PySmartKeysOptions.java index 0a2c4bc1c89f..401a85a7c3c0 100644 --- a/python/src/com/jetbrains/python/codeInsight/PySmartKeysOptions.java +++ b/python/src/com/jetbrains/python/codeInsight/PySmartKeysOptions.java @@ -10,6 +10,6 @@ import com.intellij.openapi.options.UnnamedConfigurable; public class PySmartKeysOptions extends BeanConfigurable implements UnnamedConfigurable { public PySmartKeysOptions() { super(CodeInsightSettings.getInstance()); - checkBox("INDENT_TO_CARET_ON_PASTE", "Indent pasted lines relative to caret location"); + checkBox("INDENT_TO_CARET_ON_PASTE", "Smart indent pasted lines"); } } diff --git a/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java b/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java index a392b518fdee..5f8123ae7c86 100644 --- a/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java +++ b/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java @@ -1,5 +1,6 @@ package com.jetbrains.python.editor; +import com.intellij.codeInsight.CodeInsightSettings; import com.intellij.codeInsight.editorActions.CopyPastePreProcessor; import com.intellij.openapi.editor.CaretModel; import com.intellij.openapi.editor.Document; @@ -13,6 +14,8 @@ import com.intellij.psi.PsiWhiteSpace; import com.intellij.psi.util.PsiUtilCore; import com.jetbrains.python.psi.PyFile; +import java.util.List; + /** * User : catherine */ @@ -29,23 +32,40 @@ public class PythonCopyPasteProcessor implements CopyPastePreProcessor { Editor editor, String text, RawText rawText) { + if (!CodeInsightSettings.getInstance().INDENT_TO_CARET_ON_PASTE) { + return text; + } + final CaretModel caretModel = editor.getCaretModel(); final Document document = editor.getDocument(); + String newText = text; - if (file instanceof PyFile && StringUtil.startsWithWhitespace(text) && StringUtil.endsWithLineBreak(text)) { + if (file instanceof PyFile && (StringUtil.startsWithWhitespace(text) || StringUtil.endsWithLineBreak(text) || + StringUtil.splitByLines(text).length > 1)) { + if (text.endsWith("\n")) text = text.substring(0, text.length() - 1); final int caretOffset = caretModel.getOffset(); final PsiElement element = PsiUtilCore.getElementAtOffset(file, caretOffset-1); final int lineNumber = document.getLineNumber(caretOffset); final int offset = getLineStartSafeOffset(document, lineNumber); final PsiElement element1 = PsiUtilCore.getElementAtOffset(file, offset); if (element instanceof PsiWhiteSpace && element == element1) { - caretModel.moveToOffset(offset); + final List strings = StringUtil.split(element.getText(), "\n"); + //user already prepared place to paste to and we just want to indent right + if (StringUtil.countChars(element.getText(), '\n') > 2) { + newText = text + " "; + } + else { + newText = text + "\n" + strings.get(strings.size()-1); + //pasted text'll be the only one statement in block + if (!element.getText().endsWith("\n")) + caretModel.moveToOffset(element.getTextRange().getEndOffset()); + } } } - return text; + return newText; } - public int getLineStartSafeOffset(final Document document, int line) { + public static int getLineStartSafeOffset(final Document document, int line) { if (line == document.getLineCount()) return document.getTextLength(); return document.getLineStartOffset(line); } diff --git a/python/testData/copyPaste/Indent1.after.py b/python/testData/copyPaste/Indent1.after.py index b63a962cbafe..0605eb0cbe4c 100644 --- a/python/testData/copyPaste/Indent1.after.py +++ b/python/testData/copyPaste/Indent1.after.py @@ -1,3 +1,5 @@ def bar(): x = 1 - y = 2 \ No newline at end of file + y = 2 + +var = "string" \ No newline at end of file diff --git a/python/testData/copyPaste/Indent1.dst.py b/python/testData/copyPaste/Indent1.dst.py index c5345302841c..c5fdf4163230 100644 --- a/python/testData/copyPaste/Indent1.dst.py +++ b/python/testData/copyPaste/Indent1.dst.py @@ -1,2 +1,4 @@ def bar(): - \ No newline at end of file + + +var = "string" \ No newline at end of file diff --git a/python/testData/copyPaste/Indent2.after.py b/python/testData/copyPaste/Indent2.after.py index b63a962cbafe..0605eb0cbe4c 100644 --- a/python/testData/copyPaste/Indent2.after.py +++ b/python/testData/copyPaste/Indent2.after.py @@ -1,3 +1,5 @@ def bar(): x = 1 - y = 2 \ No newline at end of file + y = 2 + +var = "string" \ No newline at end of file diff --git a/python/testData/copyPaste/Indent2.dst.py b/python/testData/copyPaste/Indent2.dst.py index c5345302841c..364124a2a6de 100644 --- a/python/testData/copyPaste/Indent2.dst.py +++ b/python/testData/copyPaste/Indent2.dst.py @@ -1,2 +1,3 @@ def bar(): - \ No newline at end of file + +var = "string" \ No newline at end of file diff --git a/python/testData/copyPaste/MethodInClass.after.py b/python/testData/copyPaste/MethodInClass.after.py new file mode 100644 index 000000000000..352ff68814d6 --- /dev/null +++ b/python/testData/copyPaste/MethodInClass.after.py @@ -0,0 +1,7 @@ +class C: + def foo(self): + x = 1 + y = 2 + + def bar(self): + pass \ No newline at end of file diff --git a/python/testData/copyPaste/MethodInClass.dst.py b/python/testData/copyPaste/MethodInClass.dst.py new file mode 100644 index 000000000000..041005c02656 --- /dev/null +++ b/python/testData/copyPaste/MethodInClass.dst.py @@ -0,0 +1,3 @@ +class C: + def bar(self): + pass \ No newline at end of file diff --git a/python/testData/copyPaste/MethodInClass.src.py b/python/testData/copyPaste/MethodInClass.src.py new file mode 100644 index 000000000000..8825aa8554cf --- /dev/null +++ b/python/testData/copyPaste/MethodInClass.src.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + \ No newline at end of file diff --git a/python/testData/copyPaste/multiLine/IndentInnerFunction.after.py b/python/testData/copyPaste/multiLine/IndentInnerFunction.after.py new file mode 100644 index 000000000000..5143a082b6bd --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentInnerFunction.after.py @@ -0,0 +1,7 @@ +class C: + def foo(self): + def foo(self): + x = 1 + y = 2 + + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentInnerFunction.dst.py b/python/testData/copyPaste/multiLine/IndentInnerFunction.dst.py new file mode 100644 index 000000000000..e05acc44d731 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentInnerFunction.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentInnerFunction.src.py b/python/testData/copyPaste/multiLine/IndentInnerFunction.src.py new file mode 100644 index 000000000000..97e2a5be4679 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentInnerFunction.src.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + \ No newline at end of file diff --git a/python/testData/copyPaste/multiLine/IndentMulti11.after.py b/python/testData/copyPaste/multiLine/IndentMulti11.after.py new file mode 100644 index 000000000000..3b76e7e258b3 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti11.after.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti11.dst.py b/python/testData/copyPaste/multiLine/IndentMulti11.dst.py new file mode 100644 index 000000000000..e05acc44d731 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti11.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti11.src.py b/python/testData/copyPaste/multiLine/IndentMulti11.src.py new file mode 100644 index 000000000000..9d884a863e58 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti11.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti12.after.py b/python/testData/copyPaste/multiLine/IndentMulti12.after.py new file mode 100644 index 000000000000..3b76e7e258b3 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti12.after.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti12.dst.py b/python/testData/copyPaste/multiLine/IndentMulti12.dst.py new file mode 100644 index 000000000000..a6d91ecf197e --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti12.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti12.src.py b/python/testData/copyPaste/multiLine/IndentMulti12.src.py new file mode 100644 index 000000000000..9d884a863e58 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti12.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti13.after.py b/python/testData/copyPaste/multiLine/IndentMulti13.after.py new file mode 100644 index 000000000000..3b76e7e258b3 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti13.after.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti13.dst.py b/python/testData/copyPaste/multiLine/IndentMulti13.dst.py new file mode 100644 index 000000000000..335c67ab2eb1 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti13.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti13.src.py b/python/testData/copyPaste/multiLine/IndentMulti13.src.py new file mode 100644 index 000000000000..9d884a863e58 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti13.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti21.after.py b/python/testData/copyPaste/multiLine/IndentMulti21.after.py new file mode 100644 index 000000000000..3b76e7e258b3 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti21.after.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti21.dst.py b/python/testData/copyPaste/multiLine/IndentMulti21.dst.py new file mode 100644 index 000000000000..e05acc44d731 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti21.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti21.src.py b/python/testData/copyPaste/multiLine/IndentMulti21.src.py new file mode 100644 index 000000000000..b014df70f891 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti21.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti22.after.py b/python/testData/copyPaste/multiLine/IndentMulti22.after.py new file mode 100644 index 000000000000..3b76e7e258b3 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti22.after.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti22.dst.py b/python/testData/copyPaste/multiLine/IndentMulti22.dst.py new file mode 100644 index 000000000000..a6d91ecf197e --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti22.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti22.src.py b/python/testData/copyPaste/multiLine/IndentMulti22.src.py new file mode 100644 index 000000000000..b014df70f891 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti22.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti23.after.py b/python/testData/copyPaste/multiLine/IndentMulti23.after.py new file mode 100644 index 000000000000..3b76e7e258b3 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti23.after.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti23.dst.py b/python/testData/copyPaste/multiLine/IndentMulti23.dst.py new file mode 100644 index 000000000000..335c67ab2eb1 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti23.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti23.src.py b/python/testData/copyPaste/multiLine/IndentMulti23.src.py new file mode 100644 index 000000000000..b014df70f891 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti23.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti31.after.py b/python/testData/copyPaste/multiLine/IndentMulti31.after.py new file mode 100644 index 000000000000..3b76e7e258b3 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti31.after.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti31.dst.py b/python/testData/copyPaste/multiLine/IndentMulti31.dst.py new file mode 100644 index 000000000000..e05acc44d731 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti31.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti31.src.py b/python/testData/copyPaste/multiLine/IndentMulti31.src.py new file mode 100644 index 000000000000..0faa3c090ddd --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti31.src.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + \ No newline at end of file diff --git a/python/testData/copyPaste/multiLine/IndentMulti32.after.py b/python/testData/copyPaste/multiLine/IndentMulti32.after.py new file mode 100644 index 000000000000..3b76e7e258b3 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti32.after.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti32.dst.py b/python/testData/copyPaste/multiLine/IndentMulti32.dst.py new file mode 100644 index 000000000000..a6d91ecf197e --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti32.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti32.src.py b/python/testData/copyPaste/multiLine/IndentMulti32.src.py new file mode 100644 index 000000000000..0faa3c090ddd --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti32.src.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + \ No newline at end of file diff --git a/python/testData/copyPaste/multiLine/IndentMulti33.after.py b/python/testData/copyPaste/multiLine/IndentMulti33.after.py new file mode 100644 index 000000000000..3b76e7e258b3 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti33.after.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti33.dst.py b/python/testData/copyPaste/multiLine/IndentMulti33.dst.py new file mode 100644 index 000000000000..335c67ab2eb1 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti33.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti33.src.py b/python/testData/copyPaste/multiLine/IndentMulti33.src.py new file mode 100644 index 000000000000..0faa3c090ddd --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti33.src.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + \ No newline at end of file diff --git a/python/testData/copyPaste/multiLine/IndentMulti41.after.py b/python/testData/copyPaste/multiLine/IndentMulti41.after.py new file mode 100644 index 000000000000..3b76e7e258b3 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti41.after.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti41.dst.py b/python/testData/copyPaste/multiLine/IndentMulti41.dst.py new file mode 100644 index 000000000000..e05acc44d731 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti41.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti41.src.py b/python/testData/copyPaste/multiLine/IndentMulti41.src.py new file mode 100644 index 000000000000..d2b89a204466 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti41.src.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + \ No newline at end of file diff --git a/python/testData/copyPaste/multiLine/IndentMulti42.after.py b/python/testData/copyPaste/multiLine/IndentMulti42.after.py new file mode 100644 index 000000000000..3b76e7e258b3 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti42.after.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti42.dst.py b/python/testData/copyPaste/multiLine/IndentMulti42.dst.py new file mode 100644 index 000000000000..a6d91ecf197e --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti42.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti42.src.py b/python/testData/copyPaste/multiLine/IndentMulti42.src.py new file mode 100644 index 000000000000..d2b89a204466 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti42.src.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + \ No newline at end of file diff --git a/python/testData/copyPaste/multiLine/IndentMulti43.after.py b/python/testData/copyPaste/multiLine/IndentMulti43.after.py new file mode 100644 index 000000000000..3b76e7e258b3 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti43.after.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti43.dst.py b/python/testData/copyPaste/multiLine/IndentMulti43.dst.py new file mode 100644 index 000000000000..335c67ab2eb1 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti43.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/multiLine/IndentMulti43.src.py b/python/testData/copyPaste/multiLine/IndentMulti43.src.py new file mode 100644 index 000000000000..d2b89a204466 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentMulti43.src.py @@ -0,0 +1,5 @@ +class C: + def foo(self): + x = 1 + y = 2 + \ No newline at end of file diff --git a/python/testData/copyPaste/singleLine/Indent11.after.py b/python/testData/copyPaste/singleLine/Indent11.after.py new file mode 100644 index 000000000000..35ce6ca060af --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent11.after.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + x = 1y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent11.dst.py b/python/testData/copyPaste/singleLine/Indent11.dst.py new file mode 100644 index 000000000000..e05acc44d731 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent11.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent11.src.py b/python/testData/copyPaste/singleLine/Indent11.src.py new file mode 100644 index 000000000000..bc46c092d973 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent11.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent12.after.py b/python/testData/copyPaste/singleLine/Indent12.after.py new file mode 100644 index 000000000000..a63cb7531a7a --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent12.after.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + x = 1 y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent12.dst.py b/python/testData/copyPaste/singleLine/Indent12.dst.py new file mode 100644 index 000000000000..a6d91ecf197e --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent12.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent12.src.py b/python/testData/copyPaste/singleLine/Indent12.src.py new file mode 100644 index 000000000000..bc46c092d973 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent12.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent13.after.py b/python/testData/copyPaste/singleLine/Indent13.after.py new file mode 100644 index 000000000000..93f1eb80f6d8 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent13.after.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + x = 1 y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent13.dst.py b/python/testData/copyPaste/singleLine/Indent13.dst.py new file mode 100644 index 000000000000..335c67ab2eb1 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent13.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent13.src.py b/python/testData/copyPaste/singleLine/Indent13.src.py new file mode 100644 index 000000000000..bc46c092d973 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent13.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent21.after.py b/python/testData/copyPaste/singleLine/Indent21.after.py new file mode 100644 index 000000000000..5b10d3ed3940 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent21.after.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent21.dst.py b/python/testData/copyPaste/singleLine/Indent21.dst.py new file mode 100644 index 000000000000..e05acc44d731 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent21.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent21.src.py b/python/testData/copyPaste/singleLine/Indent21.src.py new file mode 100644 index 000000000000..441834b71f61 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent21.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent22.after.py b/python/testData/copyPaste/singleLine/Indent22.after.py new file mode 100644 index 000000000000..5b10d3ed3940 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent22.after.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent22.dst.py b/python/testData/copyPaste/singleLine/Indent22.dst.py new file mode 100644 index 000000000000..a6d91ecf197e --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent22.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent22.src.py b/python/testData/copyPaste/singleLine/Indent22.src.py new file mode 100644 index 000000000000..441834b71f61 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent22.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent23.after.py b/python/testData/copyPaste/singleLine/Indent23.after.py new file mode 100644 index 000000000000..5b10d3ed3940 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent23.after.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent23.dst.py b/python/testData/copyPaste/singleLine/Indent23.dst.py new file mode 100644 index 000000000000..335c67ab2eb1 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent23.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent23.src.py b/python/testData/copyPaste/singleLine/Indent23.src.py new file mode 100644 index 000000000000..441834b71f61 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent23.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent31.after.py b/python/testData/copyPaste/singleLine/Indent31.after.py new file mode 100644 index 000000000000..5b10d3ed3940 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent31.after.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent31.dst.py b/python/testData/copyPaste/singleLine/Indent31.dst.py new file mode 100644 index 000000000000..e05acc44d731 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent31.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent31.src.py b/python/testData/copyPaste/singleLine/Indent31.src.py new file mode 100644 index 000000000000..7bbc1f350b88 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent31.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent32.after.py b/python/testData/copyPaste/singleLine/Indent32.after.py new file mode 100644 index 000000000000..5b10d3ed3940 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent32.after.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent32.dst.py b/python/testData/copyPaste/singleLine/Indent32.dst.py new file mode 100644 index 000000000000..a6d91ecf197e --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent32.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent32.src.py b/python/testData/copyPaste/singleLine/Indent32.src.py new file mode 100644 index 000000000000..7bbc1f350b88 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent32.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent33.after.py b/python/testData/copyPaste/singleLine/Indent33.after.py new file mode 100644 index 000000000000..5b10d3ed3940 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent33.after.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent33.dst.py b/python/testData/copyPaste/singleLine/Indent33.dst.py new file mode 100644 index 000000000000..335c67ab2eb1 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent33.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent33.src.py b/python/testData/copyPaste/singleLine/Indent33.src.py new file mode 100644 index 000000000000..7bbc1f350b88 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent33.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent41.after.py b/python/testData/copyPaste/singleLine/Indent41.after.py new file mode 100644 index 000000000000..5b10d3ed3940 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent41.after.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent41.dst.py b/python/testData/copyPaste/singleLine/Indent41.dst.py new file mode 100644 index 000000000000..e05acc44d731 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent41.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent41.src.py b/python/testData/copyPaste/singleLine/Indent41.src.py new file mode 100644 index 000000000000..ef1cd8c89d15 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent41.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent42.after.py b/python/testData/copyPaste/singleLine/Indent42.after.py new file mode 100644 index 000000000000..5b10d3ed3940 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent42.after.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent42.dst.py b/python/testData/copyPaste/singleLine/Indent42.dst.py new file mode 100644 index 000000000000..a6d91ecf197e --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent42.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent42.src.py b/python/testData/copyPaste/singleLine/Indent42.src.py new file mode 100644 index 000000000000..ef1cd8c89d15 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent42.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent43.after.py b/python/testData/copyPaste/singleLine/Indent43.after.py new file mode 100644 index 000000000000..5b10d3ed3940 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent43.after.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent43.dst.py b/python/testData/copyPaste/singleLine/Indent43.dst.py new file mode 100644 index 000000000000..335c67ab2eb1 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent43.dst.py @@ -0,0 +1,3 @@ +class C: + def foo(self): + y = 2 diff --git a/python/testData/copyPaste/singleLine/Indent43.src.py b/python/testData/copyPaste/singleLine/Indent43.src.py new file mode 100644 index 000000000000..ef1cd8c89d15 --- /dev/null +++ b/python/testData/copyPaste/singleLine/Indent43.src.py @@ -0,0 +1,4 @@ +class C: + def foo(self): + x = 1 + y = 2 diff --git a/python/testSrc/com/jetbrains/python/PyCopyPasteTest.java b/python/testSrc/com/jetbrains/python/PyCopyPasteTest.java index 3f13cf2b5598..ab16b1a19ea7 100644 --- a/python/testSrc/com/jetbrains/python/PyCopyPasteTest.java +++ b/python/testSrc/com/jetbrains/python/PyCopyPasteTest.java @@ -2,7 +2,6 @@ package com.jetbrains.python; import com.intellij.codeInsight.CodeInsightSettings; import com.intellij.openapi.actionSystem.IdeActions; -import com.intellij.openapi.util.SystemInfo; import com.jetbrains.python.fixtures.PyTestCase; /** @@ -44,18 +43,137 @@ public class PyCopyPasteTest extends PyTestCase { doTest(); } + public void testMethodInClass() { + doTest(); + } + + public void testIndent11() { + doTestSingleLine(); + } + + public void testIndent12() { + doTestSingleLine(); + } + + public void testIndent13() { + doTestSingleLine(); + } + + public void testIndent21() { + doTestSingleLine(); + } + + public void testIndent22() { + doTestSingleLine(); + } + + public void testIndent23() { + doTestSingleLine(); + } + + public void testIndent31() { + doTestSingleLine(); + } + + public void testIndent32() { + doTestSingleLine(); + } + + public void testIndent33() { + doTestSingleLine(); + } + + public void testIndent41() { + doTestSingleLine(); + } + + public void testIndent42() { + doTestSingleLine(); + } + + public void testIndent43() { + doTestSingleLine(); + } + + public void testIndentMulti11() { + doTestMultiLine(); + } + + public void testIndentMulti12() { + doTestMultiLine(); + } + + public void testIndentMulti13() { + doTestMultiLine(); + } + + public void testIndentMulti21() { + doTestMultiLine(); + } + + public void testIndentMulti22() { + doTestMultiLine(); + } + + public void testIndentMulti23() { + doTestMultiLine(); + } + + public void testIndentMulti31() { + doTestMultiLine(); + } + + public void testIndentMulti32() { + doTestMultiLine(); + } + + public void testIndentMulti33() { + doTestMultiLine(); + } + + public void testIndentMulti41() { + doTestMultiLine(); + } + + public void testIndentMulti42() { + doTestMultiLine(); + } + + public void testIndentMulti43() { + doTestMultiLine(); + } + + public void testIndentInnerFunction() { + doTestMultiLine(); + } + private void doTest() { String name = getTestName(false); - if (!SystemInfo.isWindows) { - System.out.println("PyCopyPasteTest." + name + ": system is not windows. Skipping."); - return; - } - myFixture.configureByFile("copyPaste/" + name + ".src.py"); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_COPY); myFixture.configureByFile("copyPaste/" + name + ".dst.py"); myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PASTE); myFixture.checkResultByFile("copyPaste/" + name + ".after.py"); } + + private void doTestSingleLine() { + String name = getTestName(false); + + myFixture.configureByFile("copyPaste/singleLine/" + name + ".src.py"); + myFixture.performEditorAction(IdeActions.ACTION_EDITOR_COPY); + myFixture.configureByFile("copyPaste/singleLine/" + name + ".dst.py"); + myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PASTE); + myFixture.checkResultByFile("copyPaste/singleLine/" + name + ".after.py"); + } + + private void doTestMultiLine() { + String name = getTestName(false); + + myFixture.configureByFile("copyPaste/multiLine/" + name + ".src.py"); + myFixture.performEditorAction(IdeActions.ACTION_EDITOR_COPY); + myFixture.configureByFile("copyPaste/multiLine/" + name + ".dst.py"); + myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PASTE); + myFixture.checkResultByFile("copyPaste/multiLine/" + name + ".after.py"); + } }