From e104a7c8fd86fe081d14971dba23779325507cef Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Wed, 15 Apr 2015 18:58:45 +0300 Subject: [PATCH] PY-15564 Remove text after the first backslash inside whitespace during line joining --- .../jetbrains/python/editor/PyJoinLinesHandler.java | 6 ++++++ .../BackslashBetweenTargetsInFromImport-after.py | 1 + .../joinLines/BackslashBetweenTargetsInFromImport.py | 2 ++ .../joinLines/BackslashBetweenTargetsInImport-after.py | 1 + .../joinLines/BackslashBetweenTargetsInImport.py | 2 ++ .../testSrc/com/jetbrains/python/PyJoinLinesTest.java | 10 ++++++++++ 6 files changed, 22 insertions(+) create mode 100644 python/testData/joinLines/BackslashBetweenTargetsInFromImport-after.py create mode 100644 python/testData/joinLines/BackslashBetweenTargetsInFromImport.py create mode 100644 python/testData/joinLines/BackslashBetweenTargetsInImport-after.py create mode 100644 python/testData/joinLines/BackslashBetweenTargetsInImport.py diff --git a/python/src/com/jetbrains/python/editor/PyJoinLinesHandler.java b/python/src/com/jetbrains/python/editor/PyJoinLinesHandler.java index 25ab2ef4f2a2..2631738165ac 100644 --- a/python/src/com/jetbrains/python/editor/PyJoinLinesHandler.java +++ b/python/src/com/jetbrains/python/editor/PyJoinLinesHandler.java @@ -119,6 +119,12 @@ public class PyJoinLinesHandler implements JoinRawLinesHandlerDelegate { } } } + final String sequence = text.subSequence(i + 1, end).toString(); + final int index = sequence.indexOf('\\'); + if (index >= 0) { + document.replaceString(i + 1, end, sequence.substring(0, index)); + return i + 1 + index; + } return CANNOT_JOIN; } diff --git a/python/testData/joinLines/BackslashBetweenTargetsInFromImport-after.py b/python/testData/joinLines/BackslashBetweenTargetsInFromImport-after.py new file mode 100644 index 000000000000..c5e9ca390478 --- /dev/null +++ b/python/testData/joinLines/BackslashBetweenTargetsInFromImport-after.py @@ -0,0 +1 @@ +from foo import bar, baz \ No newline at end of file diff --git a/python/testData/joinLines/BackslashBetweenTargetsInFromImport.py b/python/testData/joinLines/BackslashBetweenTargetsInFromImport.py new file mode 100644 index 000000000000..111ebe2309cb --- /dev/null +++ b/python/testData/joinLines/BackslashBetweenTargetsInFromImport.py @@ -0,0 +1,2 @@ +from foo import bar, \ + baz \ No newline at end of file diff --git a/python/testData/joinLines/BackslashBetweenTargetsInImport-after.py b/python/testData/joinLines/BackslashBetweenTargetsInImport-after.py new file mode 100644 index 000000000000..dbb57650d11d --- /dev/null +++ b/python/testData/joinLines/BackslashBetweenTargetsInImport-after.py @@ -0,0 +1 @@ +import foo, bar \ No newline at end of file diff --git a/python/testData/joinLines/BackslashBetweenTargetsInImport.py b/python/testData/joinLines/BackslashBetweenTargetsInImport.py new file mode 100644 index 000000000000..a4b81ae12319 --- /dev/null +++ b/python/testData/joinLines/BackslashBetweenTargetsInImport.py @@ -0,0 +1,2 @@ +import foo, \ + bar \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyJoinLinesTest.java b/python/testSrc/com/jetbrains/python/PyJoinLinesTest.java index cae4d6df54ed..994aa7880fa1 100644 --- a/python/testSrc/com/jetbrains/python/PyJoinLinesTest.java +++ b/python/testSrc/com/jetbrains/python/PyJoinLinesTest.java @@ -138,4 +138,14 @@ public class PyJoinLinesTest extends PyTestCase { public void testListComprehension() { doTest(); } + + // PY-15564 + public void testBackslashBetweenTargetsInImport() { + doTest(); + } + + // PY-15564 + public void testBackslashBetweenTargetsInFromImport() { + doTest(); + } }