private EditorCell getNextLeaf(EditorCell current) { if (mySide == CellSide.LEFT) { return current.getPrevLeaf(CellConditions.SELECTABLE); } else { return current.getNextLeaf(CellConditions.SELECTABLE); } }
private EditorCell findTarget(EditorCell cell) { EditorCell toRight = cell.getLeafToRight(CellConditions.SELECTABLE); if (toRight != null) { return toRight; } return cell.getNextLeaf(CellConditions.SELECTABLE); }
private boolean canExecute_internal( final KeyEvent keyEvent, final EditorContext editorContext, final SNode node, final List<SNode> selectedNodes) { if (ListSequence.fromList(selectedNodes).count() != 1) { return false; } // Selected node should be within TypeVariableDeclaration SNode selectedNode = ListSequence.fromList(selectedNodes).first(); SNode typeVarDeclaration = SNodeOperations.getAncestor( selectedNode, "jetbrains.mps.baseLanguage.structure.TypeVariableDeclaration", true, false); if (typeVarDeclaration == null) { return false; } // Next cell should belong to some other SNode, not our typeVarDeclaration jetbrains.mps.nodeEditor.cells.EditorCell selectedCell = (jetbrains.mps.nodeEditor.cells.EditorCell) editorContext.getSelectedCell(); jetbrains.mps.nodeEditor.cells.EditorCell nextLeaf = selectedCell.getNextLeaf(); if (nextLeaf == null) { return false; } SNode nextCellNode = (SNode) nextLeaf.getSNode(); return nextCellNode != null && nextCellNode != typeVarDeclaration; }
private boolean processSideDeletes(CellActionType type) { // TODO: review this logic - it was originally copied from EditorComponentKeyboardHandler final EditorCell selectedCell = getEditorCell(); if (type == CellActionType.DELETE && selectedCell.isLastPositionInBigCell() && !selectedCell.isFirstPositionInBigCell()) { final EditorCell target; if (selectedCell.isLastPositionInBigCell() && selectedCell.getContainingBigCell().getNextSibling() != null) { target = selectedCell.getContainingBigCell().getNextSibling(); } else if (selectedCell.getNextSibling() != null) { target = selectedCell.getNextSibling(); } else { target = selectedCell.getNextLeaf(CellConditions.SELECTABLE); } if (target == null || ModelAccess.instance() .runReadAction( new Computable<Boolean>() { public Boolean compute() { return target.getSNode().isAncestorOf(selectedCell.getSNode()); } })) return false; return target.executeAction(CellActionType.DELETE); } if (type == CellActionType.BACKSPACE && selectedCell.isFirstPositionInBigCell() && !selectedCell.isLastPositionInBigCell()) { final EditorCell target; if (selectedCell.isFirstPositionInBigCell() && selectedCell.getContainingBigCell().getPrevSibling() != null) { target = selectedCell.getContainingBigCell().getPrevSibling(); } else if (selectedCell.getPrevSibling() != null) { target = selectedCell.getPrevSibling(); } else { target = selectedCell.getPrevLeaf(CellConditions.SELECTABLE); } if (target == null) return false; /* if (ModelAccess.instance().runReadAction(new Computable<Boolean>() { public Boolean compute() { return target.getSNode().isAncestorOf(selectedCell.getSNode()); } })) return false; */ return target.executeAction(CellActionType.DELETE); } return false; }
private EditorCell findTarget(SelectionManager selectionManager) { Selection selection = selectionManager.getSelection(); if (selection == null) { return null; } List<EditorCell> selectedCells = selection.getSelectedCells(); EditorCell cell = myHome ? selectedCells.get(0) : selectedCells.get(selectedCells.size() - 1); EditorCell leaf = myHome ? cell.getLeafToLeft(CellConditions.SELECTABLE) : cell.getLeafToRight(CellConditions.SELECTABLE); if (leaf != null) { return leaf; } return myHome ? cell.getPrevLeaf(CellConditions.SELECTABLE) : cell.getNextLeaf(CellConditions.SELECTABLE); }
public void execute(jetbrains.mps.openapi.editor.EditorContext context) { EditorComponent editorComponent = (EditorComponent) context.getEditorComponent(); EditorCell selection = editorComponent.getSelectedCell(); editorComponent.changeSelection(selection.getNextLeaf(CellConditions.EDITABLE)); }
public boolean canExecute(jetbrains.mps.openapi.editor.EditorContext context) { EditorCell selection = ((EditorComponent) context.getEditorComponent()).getSelectedCell(); return selection != null && selection.getNextLeaf(CellConditions.EDITABLE) != null; }