From 4db548424dea672901bc70e25f3d187f21d345d3 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Mon, 1 Aug 2011 11:54:53 +0400 Subject: [PATCH] IDEA-67496 Regression: Reformat on paste: Indent Block is not working when clipboard starts with comment Corrected processing in situation when pasted text ends with empty line Corrected whole plain text replacement --- .../BlockIndentOnPasteTest.groovy | 20 +++++++++++++++++++ .../editorActions/PasteHandler.java | 5 +---- 2 files changed, 21 insertions(+), 4 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 ba85483ca036..5c0a6ccd18b5 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/editorActions/BlockIndentOnPasteTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/editorActions/BlockIndentOnPasteTest.groovy @@ -443,6 +443,26 @@ line to paste #1 doTest(before, toPaste, expected, TestFileType.TEXT) } + def testPlainTextPasteWithCompleteReplacement() { + def before = '''\ + line1 + line2\ +''' + + def toPaste = + '''\ +line to paste #1 +line to paste #2 +''' + + + def expected = '''\ +line to paste #1 +line to paste #2 +''' + doTest(before, toPaste, expected, TestFileType.TEXT) + } + def doTest(before, toPaste, expected, fileType = TestFileType.JAVA) { configureFromFileText("${getTestName(false)}.$fileType.extension", before) 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 96bf7a6fe287..2eacc170c13b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java @@ -342,11 +342,8 @@ public class PasteHandler extends EditorActionHandler { Arrays.fill(fill, ' '); String indentString = new String(fill); - for ( + for (; linesToAdjustIndent > 0; linesToAdjustIndent--) { int lineStartOffset = document.getLineStartOffset(++line); - linesToAdjustIndent > 0; - lineStartOffset = document.getLineStartOffset(++line), linesToAdjustIndent--) - { document.insertString(lineStartOffset, indentString); } }