fixed PY-6884 Paste changes code logic in case empty line inside indented block

This commit is contained in:
Ekaterina Tuzova
2012-07-12 14:06:58 +04:00
parent ec5c008967
commit 98e5444553
6 changed files with 24 additions and 17 deletions
@@ -42,23 +42,6 @@ public class PythonCopyPasteProcessor implements CopyPastePreProcessor {
final Document document = editor.getDocument();
String newText = text;
//a lot of different indents inside selected
final String[] split = StringUtil.trimTrailing(text).split("\n");
int firstIndent = 0;
int currentIndent;
for (String s : split) {
currentIndent = s.length() - s.trim().length();
if (split[0].equals(s) ) {
firstIndent = currentIndent;
}
if (!StringUtil.isEmptyOrSpaces(s) && firstIndent > currentIndent) {
if (caretModel.getLogicalPosition().column > 0)
return StringUtil.trimLeading(text);
else
return 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);
@@ -4,3 +4,4 @@ def f():
print(0.1)
else:
print(0.1)
<caret>
@@ -0,0 +1,9 @@
def foo():
if True:
a = 1
for (u, v) in range(1):
if True:
b = 1
graph.clear = 0.1
<caret>
@@ -0,0 +1,4 @@
def foo():
if True:
a = 1
<caret>
@@ -0,0 +1,6 @@
<selection>for (u, v) in range(1):
if True:
b = 1
graph.clear = 0.1
</selection>
@@ -171,6 +171,10 @@ public class PyCopyPasteTest extends PyTestCase {
doTestMultiLine();
}
public void testIndentWithEmptyLine() { //PY-6884
doTestMultiLine();
}
public void testIndentOnTopLevel() { //PY-6928
doTestSingleLine();
}