use the proper caret offset in case of selection. Do not overindent when replacing...
authorEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Tue, 12 Feb 2013 12:46:47 +0000 (16:46 +0400)
committerEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Tue, 12 Feb 2013 12:46:47 +0000 (16:46 +0400)
PY-8744 Smart indent pasted lines doesn't replace selection when pasting multi-line code

platform/lang-impl/src/com/intellij/codeInsight/editorActions/CopyPasteIndentProcessor.java

index 983e61a99a9df5b163ad0c55b90b95ef3f6e6d81..386e616102c010e1178a7ea204507315fb11924e 100644 (file)
@@ -106,7 +106,6 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor<IndentTr
           int lineNumber = initialDocument.getTextLength() > caretOffset? initialDocument.getLineNumber(caretOffset)
                                                                         : initialDocument.getLineCount() - 1;
           final int offset = getLineStartSafeOffset(initialDocument, lineNumber);
-          final int caretColumn = caretOffset - offset;
 
           if (bounds.getStartOffset() == offset) {
             String toString = initialDocument.getText(TextRange.create(offset, initialDocument.getLineEndOffset(lineNumber)));
@@ -116,8 +115,8 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor<IndentTr
                 return ch != ' ';
               }
             });
-            if (toIndent < 0 || toString.startsWith("\n")) {
-              toIndent = caretColumn;
+            if ((toIndent < 0 || toString.startsWith("\n")) && initialText.length() >= caretOffset) {
+              toIndent = caretOffset - offset;
             }
           }
           else if (isNotApplicable(initialDocument, offset))