private boolean canPasteBefore(EditorCell selectedCell, List<SNode> pasteNodes) { if (!APICellAdapter.isFirstPositionInBigCell(selectedCell)) return false; SNode anchor = selectedCell.getSNode(); if (anchor.getParent() == null) return false; NodeAndRole nodeAndRole = new NodePaster(pasteNodes).getActualAnchorNode(anchor, anchor.getRoleInParent(), false); if (nodeAndRole == null) return false; EditorCell targetCell = selectedCell.getEditorComponent().findNodeCell(nodeAndRole.myNode); return targetCell != null && ((jetbrains.mps.nodeEditor.cells.EditorCell) targetCell) .getFirstLeaf(CellConditions.SELECTABLE) == selectedCell && new NodePaster(pasteNodes).canPasteRelative(nodeAndRole.myNode); }
private boolean processSideDeletes(CellActionType type) { // TODO: review this logic - it was originally copied from EditorComponentKeyboardHandler final EditorCell selectedCell = getEditorCell(); if (type == CellActionType.DELETE && APICellAdapter.isLastPositionInBigCell(selectedCell) && !APICellAdapter.isFirstPositionInBigCell(selectedCell)) { final EditorCell target; EditorCell bigCellNextSibling = CellTraversalUtil.getNextSibling(APICellAdapter.getContainingBigCell(selectedCell)); if (bigCellNextSibling != null) { target = bigCellNextSibling; } else { EditorCell nextSibling = CellTraversalUtil.getNextSibling(APICellAdapter.getContainingBigCell(selectedCell)); if (nextSibling != null) { target = nextSibling; } else { target = CellTraversalUtil.getNextLeaf( selectedCell, jetbrains.mps.openapi.editor.cells.CellConditions.SELECTABLE); } } if (target == null || ModelAccess.instance() .runReadAction( new Computable<Boolean>() { @Override public Boolean compute() { return jetbrains.mps.util.SNodeOperations.isAncestor( target.getSNode(), selectedCell.getSNode()); } })) return false; return getEditorComponent().getActionHandler().executeAction(target, type); } if (type == CellActionType.BACKSPACE && APICellAdapter.isFirstPositionInBigCell(selectedCell) && !APICellAdapter.isLastPositionInBigCell(selectedCell)) { final EditorCell target; EditorCell bigCellPrevSibling = CellTraversalUtil.getPrevSibling(APICellAdapter.getContainingBigCell(selectedCell)); if (bigCellPrevSibling != null) { target = bigCellPrevSibling; } else { EditorCell prevSibling = CellTraversalUtil.getPrevSibling(selectedCell); if (prevSibling != null) { target = prevSibling; } else { target = CellTraversalUtil.getPrevLeaf( selectedCell, jetbrains.mps.openapi.editor.cells.CellConditions.SELECTABLE); } } if (target == null || ReadOnlyUtil.isCellReadOnly(target)) return false; /* Was commented out (again) to let some of our unit-tests be green. in particular - pressing BackSpace at this situation: <code> int a = 1; --|a; <code> where "|" is a position of cursor; if (ModelAccess.instance().runReadAction(new Computable<Boolean>() { public Boolean compute() { return jetbrains.mps.util.SNodeOperations.isAncestor(target.getSNode(), selectedCell.getSNode()); } })) return false; */ return getEditorComponent().getActionHandler().executeAction(target, type); } return false; }