mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-7524 Dragged/pasted code in wrong location
fixed PY-7470 Smart copy-paste unindents next line (in place insert)
This commit is contained in:
@@ -4,6 +4,7 @@ import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.editorActions.CopyPastePreProcessor;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.CharFilter;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -58,11 +59,16 @@ public class PythonCopyPasteProcessor implements CopyPastePreProcessor {
|
||||
final int lineOffset = getLineStartSafeOffset(document, line);
|
||||
final PsiElement ws = file.findElementAt(lineOffset);
|
||||
int offset = ws instanceof PsiWhiteSpace? ws.getTextRange().getEndOffset() : lineOffset;
|
||||
if (text.equals(selectionModel.getSelectedText())) return text;
|
||||
caretModel.moveToOffset(offset);
|
||||
selectionModel.setSelection(offset, selectionModel.getSelectionEnd());
|
||||
}
|
||||
else
|
||||
else {
|
||||
if (isNotApplicable(document, caretOffset, lineStartOffset)) {
|
||||
return text;
|
||||
}
|
||||
caretModel.moveToOffset(lineStartOffset);
|
||||
}
|
||||
String spaceString;
|
||||
int indent = 0;
|
||||
|
||||
@@ -118,8 +124,13 @@ public class PythonCopyPasteProcessor implements CopyPastePreProcessor {
|
||||
return newText;
|
||||
}
|
||||
|
||||
private boolean isNotApplicable(Document document, int caretOffset, int lineStartOffset) {
|
||||
return !StringUtil.isEmptyOrSpaces(document.getText(TextRange.create(lineStartOffset, caretOffset)));
|
||||
}
|
||||
|
||||
public static int getLineStartSafeOffset(final Document document, int line) {
|
||||
if (line == document.getLineCount()) return document.getTextLength();
|
||||
if (line < 0) return 0;
|
||||
return document.getLineStartOffset(line);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
p
|
||||
print 2rint 1
|
||||
print 3
|
||||
@@ -0,0 +1,2 @@
|
||||
p<caret>rint 1
|
||||
print 3
|
||||
@@ -0,0 +1,3 @@
|
||||
print 1<selection>
|
||||
print 2</selection>
|
||||
print 3
|
||||
@@ -0,0 +1,3 @@
|
||||
print 1
|
||||
print 2
|
||||
print 3
|
||||
@@ -0,0 +1,2 @@
|
||||
print 1<caret>
|
||||
print 3
|
||||
@@ -0,0 +1,3 @@
|
||||
print 1<selection>
|
||||
print 2</selection>
|
||||
print 3
|
||||
@@ -0,0 +1,3 @@
|
||||
print
|
||||
print 21
|
||||
print 3
|
||||
@@ -0,0 +1,2 @@
|
||||
print <caret>1
|
||||
print 3
|
||||
@@ -0,0 +1,3 @@
|
||||
print 1<selection>
|
||||
print 2</selection>
|
||||
print 3
|
||||
@@ -0,0 +1,4 @@
|
||||
class MyClass(object):
|
||||
member1 = 1
|
||||
member2 = 2
|
||||
member3 = 3
|
||||
@@ -0,0 +1,4 @@
|
||||
class MyClass(object):
|
||||
member1 = 1
|
||||
<selection> member2 = 2
|
||||
<caret></selection> member3 = 3
|
||||
@@ -0,0 +1,4 @@
|
||||
class MyClass(object):
|
||||
member1 = 1
|
||||
<selection> member2 = 2
|
||||
</selection> member3 = 3
|
||||
@@ -0,0 +1,4 @@
|
||||
class MyClass(object):
|
||||
member1 = 1
|
||||
member2 = 2
|
||||
member3 = 3
|
||||
@@ -0,0 +1,4 @@
|
||||
class MyClass(object):
|
||||
member1 = 1
|
||||
<selection><caret> member2 = 2
|
||||
</selection> member3 = 3
|
||||
@@ -0,0 +1,4 @@
|
||||
class MyClass(object):
|
||||
member1 = 1
|
||||
<selection> member2 = 2
|
||||
</selection> member3 = 3
|
||||
@@ -0,0 +1,4 @@
|
||||
class MyClass(object):
|
||||
member1 = 1
|
||||
member2 = 2
|
||||
member3 = 3
|
||||
@@ -0,0 +1,4 @@
|
||||
class MyClass(object):
|
||||
member1 = 1
|
||||
<selection> <caret>member2 = 2</selection>
|
||||
member3 = 3
|
||||
@@ -0,0 +1,4 @@
|
||||
class MyClass(object):
|
||||
member1 = 1
|
||||
<selection> member2 = 2</selection>
|
||||
member3 = 3
|
||||
@@ -0,0 +1,4 @@
|
||||
class MyClass(object):
|
||||
member1 = 1
|
||||
member2 = 2
|
||||
member3 = 3
|
||||
@@ -0,0 +1,4 @@
|
||||
class MyClass(object):
|
||||
member1 = 1
|
||||
<selection> member2 = 2<caret></selection>
|
||||
member3 = 3
|
||||
@@ -0,0 +1,4 @@
|
||||
class MyClass(object):
|
||||
member1 = 1
|
||||
<selection> member2 = 2</selection>
|
||||
member3 = 3
|
||||
@@ -227,6 +227,34 @@ public class PyCopyPasteTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLineToEnd() { //PY-7524
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLineToPrev() { //PY-7524
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLineToBegin() { //PY-7524
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSelectionOneLine() { //PY-7470
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSelectionOneLine1() { //PY-7470
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSelectionOneLine2() { //PY-7470
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSelectionOneLine3() { //PY-7470
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
String name = getTestName(false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user