public boolean canExecute(jetbrains.mps.openapi.editor.EditorContext context) { SelectionManager selectionManager = ((EditorComponent) context.getEditorComponent()).getSelectionManager(); Selection selection = selectionManager.getSelection(); if (selection instanceof SingularSelection) { SingularSelection singularSelection = (SingularSelection) selection; if (!expandSelection(singularSelection) && selectionManager.getSelectionStackSize() > 1) { return true; } EditorCell selected = singularSelection.getEditorCell(); EditorCell nextLeaf = getNextLeaf(selected); return nextLeaf != null && getCommonSelectableAncestor(selected, nextLeaf) != null; } return false; }
private boolean expandSelection(SingularSelection selection) { switch (selection.getSideSelectDirection()) { case LEFT: return mySide == CellSide.LEFT; case RIGHT: return mySide == CellSide.RIGHT; } return true; }
public void execute(jetbrains.mps.openapi.editor.EditorContext context) { SelectionManager selectionManager = ((EditorComponent) context.getEditorComponent()).getSelectionManager(); SingularSelection selection = (SingularSelection) selectionManager.getSelection(); if (!expandSelection(selection) && selectionManager.getSelectionStackSize() > 1) { selectionManager.popSelection(); return; } EditorCell selected = selection.getEditorCell(); EditorCell nextLeaf = getNextLeaf(selected); EditorCell cellToSelect = getCommonSelectableAncestor(selected, nextLeaf); Selection newSelection = selectionManager.createSelection(cellToSelect); if (newSelection instanceof SingularSelection) { ((SingularSelection) newSelection) .setSideSelectDirection( mySide == CellSide.LEFT ? SideSelectDirection.LEFT : SideSelectDirection.RIGHT); } selectionManager.pushSelection(newSelection); }