From 98e5444553aedffb38579174dfb3d55129dd12fe Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Thu, 12 Jul 2012 14:06:58 +0400 Subject: [PATCH] fixed PY-6884 Paste changes code logic in case empty line inside indented block --- .../python/editor/PythonCopyPasteProcessor.java | 17 ----------------- .../copyPaste/multiLine/IndentIfElse.after.py | 1 + .../multiLine/IndentWithEmptyLine.after.py | 9 +++++++++ .../multiLine/IndentWithEmptyLine.dst.py | 4 ++++ .../multiLine/IndentWithEmptyLine.src.py | 6 ++++++ .../com/jetbrains/python/PyCopyPasteTest.java | 4 ++++ 6 files changed, 24 insertions(+), 17 deletions(-) create mode 100644 python/testData/copyPaste/multiLine/IndentWithEmptyLine.after.py create mode 100644 python/testData/copyPaste/multiLine/IndentWithEmptyLine.dst.py create mode 100644 python/testData/copyPaste/multiLine/IndentWithEmptyLine.src.py diff --git a/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java b/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java index bfa46fc158da..0ddf46a7de80 100644 --- a/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java +++ b/python/src/com/jetbrains/python/editor/PythonCopyPasteProcessor.java @@ -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); diff --git a/python/testData/copyPaste/multiLine/IndentIfElse.after.py b/python/testData/copyPaste/multiLine/IndentIfElse.after.py index dd6316ecff23..efa8937d6b2e 100644 --- a/python/testData/copyPaste/multiLine/IndentIfElse.after.py +++ b/python/testData/copyPaste/multiLine/IndentIfElse.after.py @@ -4,3 +4,4 @@ def f(): print(0.1) else: print(0.1) + \ No newline at end of file diff --git a/python/testData/copyPaste/multiLine/IndentWithEmptyLine.after.py b/python/testData/copyPaste/multiLine/IndentWithEmptyLine.after.py new file mode 100644 index 000000000000..3ade603f37f3 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentWithEmptyLine.after.py @@ -0,0 +1,9 @@ +def foo(): + if True: + a = 1 + for (u, v) in range(1): + if True: + b = 1 + + graph.clear = 0.1 + \ No newline at end of file diff --git a/python/testData/copyPaste/multiLine/IndentWithEmptyLine.dst.py b/python/testData/copyPaste/multiLine/IndentWithEmptyLine.dst.py new file mode 100644 index 000000000000..4dcff7f3b396 --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentWithEmptyLine.dst.py @@ -0,0 +1,4 @@ +def foo(): + if True: + a = 1 + \ No newline at end of file diff --git a/python/testData/copyPaste/multiLine/IndentWithEmptyLine.src.py b/python/testData/copyPaste/multiLine/IndentWithEmptyLine.src.py new file mode 100644 index 000000000000..8885badf72ce --- /dev/null +++ b/python/testData/copyPaste/multiLine/IndentWithEmptyLine.src.py @@ -0,0 +1,6 @@ +for (u, v) in range(1): + if True: + b = 1 + + graph.clear = 0.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 6d30c6f77c2e..74d2cbab9e5e 100644 --- a/python/testSrc/com/jetbrains/python/PyCopyPasteTest.java +++ b/python/testSrc/com/jetbrains/python/PyCopyPasteTest.java @@ -171,6 +171,10 @@ public class PyCopyPasteTest extends PyTestCase { doTestMultiLine(); } + public void testIndentWithEmptyLine() { //PY-6884 + doTestMultiLine(); + } + public void testIndentOnTopLevel() { //PY-6928 doTestSingleLine(); }