mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-6410 Adding/Pasting text at the end of a class method causes the next class method to be moved outside the class
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
<resource-bundle>com.jetbrains.python.PyBundle</resource-bundle>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<copyPastePreProcessor implementation="com.jetbrains.python.editor.PythonCopyPasteProcessor"/>
|
||||
<errorHandler implementation="com.intellij.diagnostic.ITNReporter"/>
|
||||
<fileTypeFactory implementation="com.jetbrains.python.PythonFileTypeFactory"/>
|
||||
<fileTypeDetector implementation="com.jetbrains.python.PyFileTypeDetector"/>
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.jetbrains.python.editor;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.CopyPastePreProcessor;
|
||||
import com.intellij.openapi.editor.CaretModel;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.RawText;
|
||||
import com.intellij.openapi.project.Project;
|
||||
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.PsiUtilCore;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class PythonCopyPasteProcessor implements CopyPastePreProcessor {
|
||||
|
||||
@Override
|
||||
public String preprocessOnCopy(PsiFile file, int[] startOffsets, int[] endOffsets, String text) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String preprocessOnPaste(Project project,
|
||||
PsiFile file,
|
||||
Editor editor,
|
||||
String text,
|
||||
RawText rawText) {
|
||||
final CaretModel caretModel = editor.getCaretModel();
|
||||
final Document document = editor.getDocument();
|
||||
|
||||
if (StringUtil.startsWithWhitespace(text) && StringUtil.endsWithLineBreak(text)) {
|
||||
final int caretOffset = caretModel.getOffset();
|
||||
final PsiElement element = PsiUtilCore.getElementAtOffset(file, caretOffset-1);
|
||||
final int lineNumber = document.getLineNumber(caretOffset);
|
||||
final int offset = getLineStartSafeOffset(document, lineNumber);
|
||||
final PsiElement element1 = PsiUtilCore.getElementAtOffset(file, offset);
|
||||
if (element instanceof PsiWhiteSpace && element == element1) {
|
||||
caretModel.moveToOffset(offset);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public int getLineStartSafeOffset(final Document document, int line) {
|
||||
if (line == document.getLineCount()) return document.getTextLength();
|
||||
return document.getLineStartOffset(line);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class A:
|
||||
a = 1
|
||||
b = 2
|
||||
@@ -0,0 +1,2 @@
|
||||
class A:
|
||||
<caret> b = 2
|
||||
@@ -0,0 +1,3 @@
|
||||
class C:
|
||||
<selection> a = 1
|
||||
</selection>
|
||||
@@ -32,6 +32,10 @@ public class PyCopyPasteTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testIndent3() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testIndentIncrease() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user