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 5fdbc7c1c108..f445112993c1 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/editorActions/BlockIndentOnPasteTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/editorActions/BlockIndentOnPasteTest.groovy @@ -156,6 +156,23 @@ class Test { } } }\ +''' + doTest(before, toPaste, expected) + } + + void testPasteAtDocumentStartColumn() { + def before = '' + + def toPaste = + '''\ + class Test { + }\ +''' + + + def expected = '''\ +class Test { +}\ ''' doTest(before, toPaste, expected) } 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 0b0f972a203e..bff12d06df89 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java @@ -383,7 +383,7 @@ public class PasteHandler extends EditorActionHandler { final int i = CharArrayUtil.shiftBackward(chars, startOffset - 1, " \t"); // Handle situation when pasted block doesn't start new line. - if (chars.charAt(i) != '\n') { + if (i > 0 && chars.charAt(i) != '\n') { int firstNonWsOffset = CharArrayUtil.shiftForward(chars, firstLineStart, " \t"); if (firstNonWsOffset > firstLineStart) { CharSequence toInsert = chars.subSequence(firstLineStart, firstNonWsOffset);