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 3e5a2cdadb08..72b1995c8bdd 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java @@ -52,6 +52,7 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor= 0) { minIndent = Math.min(minIndent, indent); + maxIndent = Math.max(minIndent, indent); } } int firstNonSpaceChar = CharArrayUtil.shiftForward(document.getCharsSequence(), startOffsets[0], " \t"); int firstLineLeadingSpaces = (firstNonSpaceChar <= document.getLineEndOffset(selStartLine)) ? firstNonSpaceChar - startOffsets[0] : 0; - return new IndentTransferableData(minIndent, firstLineLeadingSpaces); + return new IndentTransferableData(maxIndent - minIndent, maxIndent, firstLineLeadingSpaces); } private static boolean acceptFileType(FileType fileType) { @@ -149,12 +151,17 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor strings = StringUtil.split(pastedText, "\n"); - if (caretColumn > value.getIndent() && !strings.isEmpty() && + if (realCaretColumn >= value.getIndent() && !strings.isEmpty() && StringUtil.isEmptyOrSpaces(strings.get(strings.size()-1))) endLine -=1; for (int i = startLine+1; i <= endLine; i++) { - EditorActionUtil.indentLine(project, editor, i, value.getIndent()); + int indent = value.getFirstLineLeadingSpaces() <= realCaretColumn || + value.getFirstLineLeadingSpaces() == value.getMaxIndent()? value.getIndent() : -value.getIndent(); + EditorActionUtil.indentLine(project, editor, i, indent); } indented.set(Boolean.TRUE); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/IndentTransferableData.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/IndentTransferableData.java index 1702bc02b636..503acbc14219 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/IndentTransferableData.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/IndentTransferableData.java @@ -12,10 +12,12 @@ public class IndentTransferableData implements TextBlockTransferableData, Serial private static @NonNls DataFlavor ourFlavor; private final int myIndent; + private final int myMaxIndent; private final int myFirstLineLeadingSpaces; - public IndentTransferableData(int indent, int firstLineLeadingSpaces) { + public IndentTransferableData(int indent, int maxIndent, int firstLineLeadingSpaces) { myIndent = indent; + myMaxIndent = maxIndent; myFirstLineLeadingSpaces = firstLineLeadingSpaces; } @@ -23,6 +25,10 @@ public class IndentTransferableData implements TextBlockTransferableData, Serial return myIndent; } + public int getMaxIndent() { + return myMaxIndent; + } + public int getFirstLineLeadingSpaces() { return myFirstLineLeadingSpaces; } @@ -60,6 +66,6 @@ public class IndentTransferableData implements TextBlockTransferableData, Serial } protected IndentTransferableData clone() { - return new IndentTransferableData(myIndent, myFirstLineLeadingSpaces); + return new IndentTransferableData(myIndent, myMaxIndent, myFirstLineLeadingSpaces); } } diff --git a/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java b/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java index 467dba841aab..d967259e8bc6 100644 --- a/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java +++ b/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java @@ -160,6 +160,10 @@ public class ExecUtil { return sudoAndGetOutput(scriptPath, prompt, null); } + /** + * + * @param scriptPath is already escaped filepath + */ public static ProcessOutput sudoAndGetOutput(@NotNull final String scriptPath, @NotNull final String prompt, @Nullable String workDir) throws IOException, ExecutionException {