diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java index 72b1995c8bdd..3f35700906b3 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java @@ -139,14 +139,31 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor 1)) return; - } int startLineStart = document.getLineStartOffset(startLine); // don't indent first line if there's any text before it final String textBeforeFirstLine = document.getText(new TextRange(startLineStart, bounds.getStartOffset())); + + //a lot of different indents inside selected + final String[] split = StringUtil.trimTrailing(pastedText).split("\n"); + int firstIndent = 0; + int currentIndent; + for (String s : split) { + currentIndent = s.length() - s.trim().length(); + if (split[0].equals(s) ) { + firstIndent = currentIndent; + if (currentIndent == 0) + currentIndent = textBeforeFirstLine.length(); + } + if (!StringUtil.isEmptyOrSpaces(s) && firstIndent > currentIndent) + return; + } + if (textBeforeFirstLine.trim().length() == 0) { EditorActionUtil.indentLine(project, editor, startLine, -value.getFirstLineLeadingSpaces()); }