diff --git a/python/src/com/jetbrains/python/console/PyConsoleIndentUtil.java b/python/src/com/jetbrains/python/console/PyConsoleIndentUtil.java index 83568809455c..49f16960b4ca 100644 --- a/python/src/com/jetbrains/python/console/PyConsoleIndentUtil.java +++ b/python/src/com/jetbrains/python/console/PyConsoleIndentUtil.java @@ -90,6 +90,10 @@ public class PyConsoleIndentUtil { boolean lastIndented = false; for (int i = 0; i < indentArray.length; i++) { if (!StringUtil.isEmpty(lines.get(i))) { + if (i>0 && shouldSkipNext(lines.get(i-1))) { + indentArray[i]-=indent; + continue; + } if (indentArray[i] < indent || indentArray[i] > lastIndent && !lastIndented) { indent = indentArray[i]; } @@ -123,10 +127,20 @@ public class PyConsoleIndentUtil { } public static boolean shouldIndent(@NotNull String line) { + line = stripComments(line); + return line.endsWith(":"); + } + + private static String stripComments(String line) { if (line.contains("#")) { line = line.substring(0, line.indexOf("#")); //strip comments line = line.trim(); } - return line.endsWith(":"); + return line; + } + + public static boolean shouldSkipNext(@NotNull String line) { + line = stripComments(line); + return line.endsWith(","); } } diff --git a/python/testData/console/indent6.after.py b/python/testData/console/indent6.after.py new file mode 100644 index 000000000000..31dbd181fb7c --- /dev/null +++ b/python/testData/console/indent6.after.py @@ -0,0 +1,7 @@ +class Foo: + def x(self): + b = "x".format("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") + if b: + pass \ No newline at end of file diff --git a/python/testData/console/indent6.py b/python/testData/console/indent6.py new file mode 100644 index 000000000000..6213c78f7a98 --- /dev/null +++ b/python/testData/console/indent6.py @@ -0,0 +1,7 @@ + class Foo: + def x(self): + b = "x".format("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") + if b: + pass \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyConsoleIndentTest.java b/python/testSrc/com/jetbrains/python/PyConsoleIndentTest.java index 8deef4254f68..28ea147a4508 100644 --- a/python/testSrc/com/jetbrains/python/PyConsoleIndentTest.java +++ b/python/testSrc/com/jetbrains/python/PyConsoleIndentTest.java @@ -31,6 +31,10 @@ public class PyConsoleIndentTest extends UsefulTestCase{ doTest(); } + public void testIndent6() { + doTest(); + } + private void doTest() { String name = getTestName(true); try {