From 692907014ed8492ea6f1896e93fbc2db94287ab5 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 23 Aug 2012 13:53:48 +0200 Subject: [PATCH] when joining comments, we skipped over whitespace to the left of caret twice, which caused characters to be deleted (PY-7286) --- .../src/com/jetbrains/python/editor/PyJoinLinesHandler.java | 6 +----- python/testData/joinLines/TwoComments2-after.py | 1 + python/testData/joinLines/TwoComments2.py | 2 ++ python/testSrc/com/jetbrains/python/PyJoinLinesTest.java | 1 + .../testSrc/com/jetbrains/python/PythonAllTestsSuite.java | 3 ++- 5 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 python/testData/joinLines/TwoComments2-after.py create mode 100644 python/testData/joinLines/TwoComments2.py diff --git a/python/src/com/jetbrains/python/editor/PyJoinLinesHandler.java b/python/src/com/jetbrains/python/editor/PyJoinLinesHandler.java index 4abd4cd5e7de..6afb2274409a 100644 --- a/python/src/com/jetbrains/python/editor/PyJoinLinesHandler.java +++ b/python/src/com/jetbrains/python/editor/PyJoinLinesHandler.java @@ -420,11 +420,7 @@ public class PyJoinLinesHandler implements JoinRawLinesHandlerDelegate { int last = right_range.getEndOffset(); while (pos < last && " \t".indexOf(text.charAt(pos)) >= 0) pos += 1; int right = pos - initial_pos + 1; // account for the '#' - initial_pos = req.leftElem().getTextRange().getEndOffset() - 1; - pos = initial_pos; - while (" \t".indexOf(text.charAt(pos)) >= 0) pos -=1; // we'll end up at '#' if nothing else - int left = initial_pos - pos; - return new Result(" ", 0, left, right); + return new Result(" ", 0, 0, right); } return null; } diff --git a/python/testData/joinLines/TwoComments2-after.py b/python/testData/joinLines/TwoComments2-after.py new file mode 100644 index 000000000000..902659a400b9 --- /dev/null +++ b/python/testData/joinLines/TwoComments2-after.py @@ -0,0 +1 @@ + # has the diff --git a/python/testData/joinLines/TwoComments2.py b/python/testData/joinLines/TwoComments2.py new file mode 100644 index 000000000000..0f6d7f325e6f --- /dev/null +++ b/python/testData/joinLines/TwoComments2.py @@ -0,0 +1,2 @@ + # has + # the diff --git a/python/testSrc/com/jetbrains/python/PyJoinLinesTest.java b/python/testSrc/com/jetbrains/python/PyJoinLinesTest.java index eea44eba889e..93234c071898 100644 --- a/python/testSrc/com/jetbrains/python/PyJoinLinesTest.java +++ b/python/testSrc/com/jetbrains/python/PyJoinLinesTest.java @@ -61,6 +61,7 @@ public class PyJoinLinesTest extends PyTestCase { public void testTuple() { doTest(); } public void testTupleRPar() { doTest(); } public void testTwoComments() { doTest(); } + public void testTwoComments2() { doTest(); } // PY-7286 public void testTwoStatements() { doTest(); } public void testStringWithSlash() { doTest(); } public void testListOfStrings() { doTest(); } diff --git a/python/testSrc/com/jetbrains/python/PythonAllTestsSuite.java b/python/testSrc/com/jetbrains/python/PythonAllTestsSuite.java index 8fa6839a8776..a7dc71ab0544 100644 --- a/python/testSrc/com/jetbrains/python/PythonAllTestsSuite.java +++ b/python/testSrc/com/jetbrains/python/PythonAllTestsSuite.java @@ -98,7 +98,8 @@ public class PythonAllTestsSuite { PyMissingConstructorTest.class, PyPropertyAccessInspectionTest.class, Jinja2ParserTest.class, - DjangoTemplateParserTest.class + DjangoTemplateParserTest.class, + PyJoinLinesTest.class }; public static TestSuite suite() {