Пример #1
0
 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;
 }
Пример #2
0
 private boolean expandSelection(SingularSelection selection) {
   switch (selection.getSideSelectDirection()) {
     case LEFT:
       return mySide == CellSide.LEFT;
     case RIGHT:
       return mySide == CellSide.RIGHT;
   }
   return true;
 }
Пример #3
0
 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);
 }