PY-18522 "Smart indent on paste" preserves original indent of statement if necessary

This commit is contained in:
Mikhail Golubev
2016-03-28 15:12:29 +03:00
parent 6045ea45eb
commit 0bfd1b6cca
5 changed files with 23 additions and 1 deletions

View File

@@ -162,8 +162,10 @@ public class PythonCopyPasteProcessor implements CopyPastePreProcessor {
indentText = strings.get(0); indentText = strings.get(0);
} }
} }
if (indentText.length() == firstLineIndent) // Top-level, there should be no indentation
if (PsiTreeUtil.getParentOfType(ws, PyStatementList.class) == null) {
return ""; return "";
}
} }
return indentText; return indentText;
} }

View File

@@ -0,0 +1,5 @@
def f():
x = 1
z = 3
y = 2

View File

@@ -0,0 +1,4 @@
def f():
x = 1
<caret>
y = 2

View File

@@ -0,0 +1,6 @@
def f():
x = 1
y = 2
<selection> z = 3
</selection>

View File

@@ -371,4 +371,9 @@ public class PyCopyPasteTest extends PyTestCase {
private void doTestMultiLine() { private void doTestMultiLine() {
doTest("multiLine/"); doTest("multiLine/");
} }
// PY-18522
public void testSameIndentPreserved() {
doTest();
}
} }