mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
fixed PY-6907 Paste leads to syntactically incorrect code in case of dedent in copied text
This commit is contained in:
@@ -42,6 +42,23 @@ public class PythonCopyPasteProcessor implements CopyPastePreProcessor {
|
||||
final Document document = editor.getDocument();
|
||||
String newText = text;
|
||||
|
||||
//a lot of different indents inside selected
|
||||
final String[] split = StringUtil.trimTrailing(text).split("\n");
|
||||
int firstIndent = 0;
|
||||
int currentIndent;
|
||||
for (String s : split) {
|
||||
currentIndent = s.length() - s.trim().length();
|
||||
if (split[0].equals(s) ) {
|
||||
firstIndent = currentIndent;
|
||||
}
|
||||
if (!StringUtil.isEmptyOrSpaces(s) && firstIndent > currentIndent) {
|
||||
if (caretModel.getLogicalPosition().column > 0)
|
||||
return StringUtil.trimLeading(text);
|
||||
else
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
if (file instanceof PyFile && (StringUtil.startsWithWhitespace(text) || StringUtil.endsWithLineBreak(text) ||
|
||||
StringUtil.splitByLines(text).length > 1)) {
|
||||
if (text.endsWith("\n")) text = text.substring(0, text.length() - 1);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
def f():
|
||||
if True:
|
||||
a = 1
|
||||
print(0.1)
|
||||
else:
|
||||
print(0.1)
|
||||
4
python/testData/copyPaste/multiLine/IndentIfElse.dst.py
Normal file
4
python/testData/copyPaste/multiLine/IndentIfElse.dst.py
Normal file
@@ -0,0 +1,4 @@
|
||||
def f():
|
||||
if True:
|
||||
a = 1
|
||||
<caret>
|
||||
6
python/testData/copyPaste/multiLine/IndentIfElse.src.py
Normal file
6
python/testData/copyPaste/multiLine/IndentIfElse.src.py
Normal file
@@ -0,0 +1,6 @@
|
||||
def f():
|
||||
if False:
|
||||
<selection> print(0.1)
|
||||
else:
|
||||
print(0.1)
|
||||
</selection>
|
||||
@@ -167,6 +167,10 @@ public class PyCopyPasteTest extends PyTestCase {
|
||||
doTestMultiLine();
|
||||
}
|
||||
|
||||
public void testIndentIfElse() { //PY-6907
|
||||
doTestMultiLine();
|
||||
}
|
||||
|
||||
public void testIndentOnTopLevel() { //PY-6928
|
||||
doTestSingleLine();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user