IDEA-85646 Paste reformats near lines even when "Indent each line" is selected in "Reformat on paste"

This commit is contained in:
Denis.Zhdanov
2012-05-04 15:40:01 +04:00
parent e4ee91a2e7
commit 0454dd12ad
@@ -327,6 +327,31 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
final CharSequence text = editor.getDocument().getCharsSequence();
if (startOffset > 0 && endOffset > startOffset + 1 && text.charAt(endOffset - 1) == '\n' && text.charAt(startOffset - 1) == '\n') {
// There is a possible situation that pasted text ends by a line feed. We don't want to proceed it when a text is
// pasted at the first line column.
// Example:
// text to paste:
//'if (true) {
//'
// source:
// if (true) {
// int i = 1;
// int j = 1;
// }
//
//
// We get the following on paste then:
// if (true) {
// if (true) {
// int i = 1;
// int j = 1;
// }
//
// We don't want line 'int i = 1;' to be indented here.
endOffset--;
}
try {
codeStyleManager.adjustLineIndent(file, new TextRange(startOffset, endOffset));
}