From 0454dd12ad7f0c2df4a98b4ea2eb9be54a40d358 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Fri, 4 May 2012 15:39:41 +0400 Subject: [PATCH] IDEA-85646 Paste reformats near lines even when "Indent each line" is selected in "Reformat on paste" --- .../editorActions/PasteHandler.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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 d2a99b30e253..1dbf5c2dd5cc 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java @@ -327,6 +327,31 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project); + final CharSequence text = editor.getDocument().getCharsSequence(); + if (startOffset > 0 && endOffset > startOffset + 1 && text.charAt(endOffset - 1) == '\n' && text.charAt(startOffset - 1) == '\n') { + // There is a possible situation that pasted text ends by a line feed. We don't want to proceed it when a text is + // pasted at the first line column. + // Example: + // text to paste: + //'if (true) { + //' + // source: + // if (true) { + // int i = 1; + // int j = 1; + // } + // + // + // We get the following on paste then: + // if (true) { + // if (true) { + // int i = 1; + // int j = 1; + // } + // + // We don't want line 'int i = 1;' to be indented here. + endOffset--; + } try { codeStyleManager.adjustLineIndent(file, new TextRange(startOffset, endOffset)); }