mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-6927 Paste always pastes copied text to the second indent level regardless caret position when pasting to the end of the function
This commit is contained in:
@@ -11,10 +11,9 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiWhiteSpace;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.PyFile;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import com.jetbrains.python.psi.PyStatementList;
|
||||
|
||||
import java.util.List;
|
||||
@@ -54,14 +53,8 @@ public class PythonCopyPasteProcessor implements CopyPastePreProcessor {
|
||||
final PsiElement element1 = PsiUtilCore.getElementAtOffset(file, offset);
|
||||
boolean moved = false;
|
||||
if (element instanceof PsiWhiteSpace && element == element1) {
|
||||
final PsiElement prevSibling = element.getPrevSibling();
|
||||
PyStatementList statementList = null;
|
||||
if (prevSibling instanceof PyFunction) {
|
||||
statementList = ((PyFunction)prevSibling).getStatementList();
|
||||
}
|
||||
else if (prevSibling instanceof PyClass) {
|
||||
statementList = ((PyClass)prevSibling).getStatementList();
|
||||
}
|
||||
PyStatementList statementList = PsiTreeUtil
|
||||
.findElementOfClassAtOffset(file, element.getTextOffset() - 1, PyStatementList.class, false);
|
||||
// Caret beyond actual indent -- move to the actual offset
|
||||
if (statementList != null) {
|
||||
final PsiElement lastChild = statementList.getLastChild();
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
def f(self):
|
||||
x = 1
|
||||
if True:
|
||||
b = 2
|
||||
x = 1
|
||||
<caret>
|
||||
@@ -0,0 +1,5 @@
|
||||
def f(self):
|
||||
x = 1
|
||||
if True:
|
||||
b = 2
|
||||
<caret>
|
||||
@@ -0,0 +1,4 @@
|
||||
def f(self):
|
||||
<selection> x = 1</selection>
|
||||
if True:
|
||||
b = 2
|
||||
@@ -171,6 +171,10 @@ public class PyCopyPasteTest extends PyTestCase {
|
||||
doTestSingleLine();
|
||||
}
|
||||
|
||||
public void testIndentInIfInDef() { //PY-6927
|
||||
doTestSingleLine();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
String name = getTestName(false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user