diff --git a/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java b/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java index 137d87eea46a..8ae2ade549b6 100644 --- a/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java +++ b/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java @@ -113,7 +113,7 @@ public class PythonCopyPasteProcessor implements CopyPastePreProcessor { newText = new String(text); // to indent correctly (see PasteHandler) } - if (element instanceof PsiWhiteSpace && + if ((element instanceof PsiWhiteSpace || element.getTextOffset() == 0) && (StringUtil.countChars(element.getText(), '\n') <= 2 && !StringUtil.isEmptyOrSpaces(text))) { newText += "\n"; } diff --git a/python/testData/copyPaste/BeginningOfFile.after.py b/python/testData/copyPaste/BeginningOfFile.after.py new file mode 100644 index 000000000000..663a4618bbc9 --- /dev/null +++ b/python/testData/copyPaste/BeginningOfFile.after.py @@ -0,0 +1,3 @@ +a = 1 +b = 2 +a = 1 \ No newline at end of file diff --git a/python/testData/copyPaste/BeginningOfFile.dst.py b/python/testData/copyPaste/BeginningOfFile.dst.py new file mode 100644 index 000000000000..991d8ef2dab4 --- /dev/null +++ b/python/testData/copyPaste/BeginningOfFile.dst.py @@ -0,0 +1,2 @@ +b = 2 +a = 1 \ No newline at end of file diff --git a/python/testData/copyPaste/BeginningOfFile.src.py b/python/testData/copyPaste/BeginningOfFile.src.py new file mode 100644 index 000000000000..9f58dbcebdbf --- /dev/null +++ b/python/testData/copyPaste/BeginningOfFile.src.py @@ -0,0 +1,3 @@ +b = 2 +a = 1 + \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyCopyPasteTest.java b/python/testSrc/com/jetbrains/python/PyCopyPasteTest.java index 30e63e9a6b01..2c515b000a74 100644 --- a/python/testSrc/com/jetbrains/python/PyCopyPasteTest.java +++ b/python/testSrc/com/jetbrains/python/PyCopyPasteTest.java @@ -255,6 +255,10 @@ public class PyCopyPasteTest extends PyTestCase { doTest(); } + public void testBeginningOfFile() { //PY-7524 + doTest(); + } + private void doTest() { String name = getTestName(false);