@Override public void execute(EditorContext context) { EditorComponent editorComponent = (EditorComponent) context.getEditorComponent(); editorComponent.clearSelectionStack(); editorComponent.changeSelection( CellFinderUtil.findLastSelectableLeaf(EditorCell_Collection.this)); }
@Override public void selectionChanged( jetbrains.mps.openapi.editor.EditorComponent editorComponent, Selection oldSelection, Selection newSelection) { if (oldSelection == newSelection) { return; } if (myClosingBrace.isSelected() || myOpeningBrace.isSelected()) { enableBraces(); return; } EditorCell deepestSelection = editorComponent.getDeepestSelectedCell(); EditorCell lastSelectableLeaf = CellFinderUtil.findChildByCondition( EditorCell_Collection.this, LAST_SELECTABLE_LEAF_EXCLUDING_BRACE, false); EditorCell firstSelectableLeaf = CellFinderUtil.findChildByCondition( EditorCell_Collection.this, FIRST_SELECTABLE_LEAF_EXCLUDING_BRACE, true); if (deepestSelection instanceof EditorCell_Brace) { EditorCell_Collection braceOwner = (EditorCell_Collection) deepestSelection.getParent(); if (braceOwner.myClosingBrace == deepestSelection && CellFinderUtil.findChildByCondition( braceOwner, LAST_SELECTABLE_LEAF_EXCLUDING_BRACE, false) == lastSelectableLeaf) { enableBraces(); return; } if (braceOwner.myOpeningBrace == deepestSelection && CellFinderUtil.findChildByCondition( braceOwner, FIRST_SELECTABLE_LEAF_EXCLUDING_BRACE, true) == firstSelectableLeaf) { enableBraces(); return; } } if (lastSelectableLeaf == deepestSelection || firstSelectableLeaf == deepestSelection) { enableBraces(); } else { disableBraces(); } }
private boolean isDescendantCellSelected(EditorComponent editorComponent) { EditorCell selectedCell = editorComponent.getDeepestSelectedCell(); return selectedCell != null && CellFinderUtil.findParent( selectedCell, new Condition<jetbrains.mps.openapi.editor.cells.EditorCell_Collection>() { @Override public boolean met( jetbrains.mps.openapi.editor.cells.EditorCell_Collection object) { return object == EditorCell_Collection.this; } }) != null; }
@Override public boolean canExecute(EditorContext context) { return EditorCell_Collection.this.isSelected() && CellFinderUtil.findLastSelectableLeaf(EditorCell_Collection.this) != null; }