use the proper caret offset in case of selection. Do not overindent when replacing selection

PY-8744 Smart indent pasted lines doesn't replace selection when pasting multi-line code
This commit is contained in:
Ekaterina Tuzova
2013-02-12 16:46:45 +04:00
parent 2dc50cdbc5
commit aeb7b075c6
5 changed files with 16 additions and 1 deletions
@@ -58,7 +58,7 @@ public class PythonCopyPasteProcessor implements CopyPastePreProcessor {
final int line = document.getLineNumber(selectionModel.getSelectionStart());
final int lineOffset = getLineStartSafeOffset(document, line);
final PsiElement ws = file.findElementAt(lineOffset);
int offset = ws instanceof PsiWhiteSpace? ws.getTextRange().getEndOffset() : caretOffset;
int offset = ws instanceof PsiWhiteSpace? ws.getTextRange().getEndOffset() : selectionModel.getSelectionStart();
if (text.equals(selectionModel.getSelectedText())) return text;
caretModel.moveToOffset(offset);
selectionModel.setSelection(offset, selectionModel.getSelectionEnd());
@@ -0,0 +1,4 @@
a = 1
b = 1
a = 1
b = 1
@@ -0,0 +1,4 @@
a = 1
b = 1
<selection>c = 1
</selection><caret>
@@ -0,0 +1,3 @@
<selection>a = 1
b = 1
</selection><caret>c = 1
@@ -263,6 +263,10 @@ public class PyCopyPasteTest extends PyTestCase {
doTest();
}
public void testReplaceSelection() { //PY-8744
doTest();
}
private void doTest() {
String name = getTestName(false);