From a10c9beb07a5df7e040edbcf970e177d6e69d42a Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Mon, 28 Nov 2011 18:40:25 +0300 Subject: [PATCH] [by: nicity] IDEA-77340 Incorrect indentation on pasting a method with empty line before (in Indent Block mode) 1. Doc comment is added; 2. Test is added; --- .../BlockIndentOnPasteTest.groovy | 39 ++++++++++++++++++- .../editorActions/PasteHandler.java | 14 ++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/editorActions/BlockIndentOnPasteTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/editorActions/BlockIndentOnPasteTest.groovy index 8a1d40db7617..23e2dcadaf3f 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/editorActions/BlockIndentOnPasteTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/editorActions/BlockIndentOnPasteTest.groovy @@ -580,7 +580,44 @@ class Test { ''' doTest(before, toPaste2, expected2) } - + + void testPasteMultilineTextThatStartsWithLineFeedToNewLineWithBigCaretIndent() { + def before = '''\ + class Test { + void test(int i) { + if (i > 0) { + + } + } + }\ +''' + + def toPaste = ''' + test(1); + test(1);\ +''' + + def expected = '''\ + class Test { + void test(int i) { + if (i > 0) { + + test(1); + test(1); + } + } + }\ +''' + doTest(before, toPaste, expected) + + + def toPaste2 = ''' + test(1); + test(1);\ +''' + doTest(before, toPaste2, expected) + } + def testPlainTextPaste() { def before = '''\ line1 diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java index a6032804a2ec..cf58f40d2c16 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java @@ -519,7 +519,19 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser } return; } - + + // We've pasted text to the non-first column and exact white space between the line start and caret position on the moment of paste + // has been removed by formatter during 'adjust line indent' + // Example: + // copied text: + // ' line1 + // line2' + // after paste: + // line start -> ' I line1 + // line2' (I - caret position during 'paste') + // formatter removed white space between the line start and caret position, so, current document state is: + // ' line1 + // line2' if (anchorLine == firstLine && -diff == startOffset - firstLineStart) { return; }