String (PsiFile file, int[] startOffsets, int[] endOffsets, String text) { if (!CodeInsightSettings.getInstance().INDENT_TO_CARET_ON_PASTE || !isSupportedFile(file)) { return null; } // Expand copied text if it can cause indentation ambiguity // Text was selected with a single caret and might begin with a block statement if (startOffsets.length == 1 && endOffsets.length == 1 && fragmentBeginsWithBlockStatement(text)) { final int start = startOffsets[0]; final int end = endOffsets[0]; final Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file); if (document != null) { final int startLine = document.getLineNumber(start); final int startLineOffset = getLineStartSafeOffset(document, startLine); if (start != startLineOffset && startLine != document.getLineNumber(end)) { final PsiElement keyword = file.findElementAt(start); if (keyword != null && START_KEYWORDS.contains(keyword.getText())) { final PyStatementListContainer block = PsiTreeUtil.getParentOfType(keyword, PyStatementListContainer.class); // Statement body is in selection if (block != null && end > block.getStatementList().getTextOffset()) { final String linePrefix = document.getText(TextRange.create(startLineOffset, start)); if (StringUtil.isEmptyOrSpaces(linePrefix)) { return linePrefix + text; } } } } } } return null; }