mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-6928 Paste inserts code one line after caret and messes up code in case for as the last compound statement in function
PY-6907 Paste leads to syntactically incorrect code in case of dedent in copied text
This commit is contained in:
+20
-3
@@ -139,14 +139,31 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor<IndentTr
|
||||
|
||||
int startLine = document.getLineNumber(bounds.getStartOffset());
|
||||
int endLine = document.getLineNumber(bounds.getEndOffset());
|
||||
if (!pastedText.trim().contains("\n") && startLine == endLine) {
|
||||
// don't indent single-line text
|
||||
|
||||
// don't indent single-line text
|
||||
if (!StringUtil.startsWithWhitespace(pastedText) && !StringUtil.endsWithLineBreak(pastedText) &&
|
||||
!(StringUtil.splitByLines(pastedText).length > 1))
|
||||
return;
|
||||
}
|
||||
|
||||
int startLineStart = document.getLineStartOffset(startLine);
|
||||
// don't indent first line if there's any text before it
|
||||
final String textBeforeFirstLine = document.getText(new TextRange(startLineStart, bounds.getStartOffset()));
|
||||
|
||||
//a lot of different indents inside selected
|
||||
final String[] split = StringUtil.trimTrailing(pastedText).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 (currentIndent == 0)
|
||||
currentIndent = textBeforeFirstLine.length();
|
||||
}
|
||||
if (!StringUtil.isEmptyOrSpaces(s) && firstIndent > currentIndent)
|
||||
return;
|
||||
}
|
||||
|
||||
if (textBeforeFirstLine.trim().length() == 0) {
|
||||
EditorActionUtil.indentLine(project, editor, startLine, -value.getFirstLineLeadingSpaces());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user