boolean (@NotNull Editor editor, @NotNull PsiFile file, @NotNull MoveInfo info, boolean down) { if (!(file instanceof PyFile)) return false; final int offset = editor.getCaretModel().getOffset(); final SelectionModel selectionModel = editor.getSelectionModel(); final Document document = editor.getDocument(); final int lineNumber = document.getLineNumber(offset); int start = getLineStartSafeOffset(document, lineNumber); final int lineEndOffset = document.getLineEndOffset(lineNumber); int end = lineEndOffset == 0 ? 0 : lineEndOffset - 1; if (selectionModel.hasSelection()) { start = selectionModel.getSelectionStart(); final int selectionEnd = selectionModel.getSelectionEnd(); end = selectionEnd == 0 ? 0 : selectionEnd - 1; } PsiElement elementToMove1 = PyUtil.findNonWhitespaceAtOffset(file, start); PsiElement elementToMove2 = PyUtil.findNonWhitespaceAtOffset(file, end); if (elementToMove1 == null || elementToMove2 == null) return false; if (ifInsideString(document, lineNumber, elementToMove1, down)) return false; elementToMove1 = getCommentOrStatement(document, elementToMove1); elementToMove2 = getCommentOrStatement(document, elementToMove2); if (PsiTreeUtil.isAncestor(elementToMove1, elementToMove2, false)) { elementToMove2 = elementToMove1; } else if (PsiTreeUtil.isAncestor(elementToMove2, elementToMove1, false)) { elementToMove1 = elementToMove2; } else { PsiElement commonParent = PsiTreeUtil.findCommonParent(elementToMove1, elementToMove2); if (commonParent == null) return false; elementToMove1 = PyPsiUtils.getParentRightBefore(elementToMove1, commonParent); elementToMove2 = PyPsiUtils.getParentRightBefore(elementToMove2, commonParent); assert elementToMove1 != null && elementToMove2 != null; } info.toMove = new MyLineRange(elementToMove1, elementToMove2); info.toMove2 = getDestinationScope(file, editor, down ? elementToMove2 : elementToMove1, down); info.indentTarget = false; info.indentSource = false; return true; }