diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavadocFormatterTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavadocFormatterTest.java index 97fa3d2c30ec..24adb297bce6 100644 --- a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavadocFormatterTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavadocFormatterTest.java @@ -605,4 +605,17 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest { doTextTest(before, after); } + + public void testDoNotWrapLongLineCommentWithSpaceInStart() throws Exception { + getSettings().KEEP_FIRST_COLUMN_COMMENT = true; + getSettings().WRAP_LONG_LINES = true; + getSettings().getRootSettings().RIGHT_MARGIN = 200; + String before = "public class JiraIssue {\n" + + "\n" + + " public static void main(String[] args) {\n" + + "// AAAMIIGgIBADANBgkqhkiG9w0BAQEFAASCBugwgsdfssdflkldkflskdfsdkfjskdlfjdskjfksdjfksdjfkjsdkfjsdkfjgbkAgEAAoIBgQCZfKds4XjFWIU8D4OqCYJ0TkAkKPVV96v2l6PuMBNbON3ndHCVvwoJOJnopfbtFro9eCTCUC9MlAUZBAVdCbPVi3ioqaEN\n" + + " }\n" + + "}"; + doTextTest(before, before); + } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java index ebf21734d4b8..8ef61c8be297 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeFormatterFacade.java @@ -491,9 +491,17 @@ public class CodeFormatterFacade { editor.getCaretModel().moveToOffset(wrapOffset); emulateEnter(editor, project, shifts); - // We know that number of lines is just increased, hence, update the data accordingly. - maxLine += shifts[0]; - endOffsetToUse += shifts[1]; + //If number of inserted symbols on new line after wrapping more or equal then symbols left on previous line + //there was no point to wrapping it, so reverting to before wrapping version + if (shifts[1] - 1 >= wrapOffset - startLineOffset) { + document.deleteString(wrapOffset, wrapOffset + shifts[1]); + } + else { + // We know that number of lines is just increased, hence, update the data accordingly. + maxLine += shifts[0]; + endOffsetToUse += shifts[1]; + } + } } @@ -504,7 +512,7 @@ public class CodeFormatterFacade { * @param project target project * @param shifts two-elements array which is expected to be filled with the following info: * 1. The first element holds added lines number; - * 2. The second element holds added symbols number; + * 2. The second element holds added symbols number; */ private static void emulateEnter(@NotNull final Editor editor, @NotNull Project project, int[] shifts) { final DataContext dataContext = prepareContext(editor.getComponent(), project);