コード例 #1
0
 @Override
 public void execute(final jetbrains.mps.openapi.editor.EditorContext context) {
   EditorComponent editorComponent = ((EditorComponent) context.getEditorComponent());
   SelectionManager selectionManager = editorComponent.getSelectionManager();
   Selection selection = selectionManager.getSelection();
   if (selection instanceof SingularSelection) {
     EditorCell selectedCell = ((SingularSelection) selection).getEditorCell();
     SNode selectedNode = selectedCell.getSNode();
     SNode topMostNodeInSingularContainment =
         findTopMostNodeWithSingularContainment(selectedNode);
     if (topMostNodeInSingularContainment != selectedNode) {
       EditorCell nodeCell = editorComponent.findNodeCell(topMostNodeInSingularContainment);
       if (nodeCell != null) {
         editorComponent.pushSelection(nodeCell);
         editorComponent.scrollToCell(nodeCell);
       }
     } else {
       Selection newSelection =
           selectionManager.createRangeSelection(selectedNode, selectedNode);
       if (newSelection instanceof NodeRangeSelection && selectedCell.isBigCell()) {
         newSelection = ((NodeRangeSelection) newSelection).enlargeSelection(myUp);
       }
       if (newSelection != null) {
         selectionManager.pushSelection(newSelection);
         newSelection.ensureVisible();
       }
     }
   } else if (selection instanceof NodeRangeSelection) {
     Selection newSelection = ((NodeRangeSelection) selection).enlargeSelection(myUp);
     if (newSelection != null) {
       selectionManager.pushSelection(newSelection);
       newSelection.ensureVisible();
     }
   }
 }
コード例 #2
0
    public void execute_internal(EditorContext editorContext, SNode node) {
      SNode expression = SLinkOperations.getTarget(node, "processHandler", true);
      SNodeOperations.replaceWithAnother(node, expression);

      // some stuff I copied from binary operation
      // it does some magic with selection
      editorContext.flushEvents();
      EditorComponent editor = editorContext.getEditorComponent();
      EditorCell cell = (EditorCell) editor.findNodeCell(expression);
      if (cell != null) {
        EditorCell lastLeaf = cell.getLastLeaf(CellConditions.SELECTABLE);
        editor.changeSelection(lastLeaf);
        if (lastLeaf instanceof EditorCell_Label) {
          ((EditorCell_Label) lastLeaf).end();
        }
      }
    }