Esempio n. 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();
     }
   }
 }
Esempio n. 2
0
 public void execute(jetbrains.mps.openapi.editor.EditorContext context) {
   SelectionManager selectionManager =
       ((EditorComponent) context.getEditorComponent()).getSelectionManager();
   EditorCell cell = findTarget(selectionManager);
   selectionManager.pushSelection(selectionManager.createSelection(cell));
   if (cell instanceof EditorCell_Label) {
     ((EditorCell_Label) cell).selectWordOrAll();
   }
 }
Esempio n. 3
0
 public void execute(jetbrains.mps.openapi.editor.EditorContext context) {
   SelectionManager selectionManager =
       ((EditorComponent) context.getEditorComponent()).getSelectionManager();
   EditorCell cell = findTarget(selectionManager);
   selectionManager.setSelection(cell);
   if (cell.isPunctuationLayout()
       && (cell instanceof EditorCell_Label)
       && ((EditorCell_Label) cell).isCaretPositionAllowed(1)) {
     ((EditorCell_Label) cell).setCaretPosition(1);
   } else {
     cell.home();
   }
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
    private EditorCell findTarget(SelectionManager selectionManager) {
      Selection selection = selectionManager.getSelection();
      if (selection == null) {
        return null;
      }

      jetbrains.mps.openapi.editor.cells.EditorCell cell = selection.getSelectedCells().get(0);
      if (cell instanceof EditorCell_Label && !((EditorCell_Label) cell).isEverythingSelected()) {
        return (EditorCell) cell;
      }

      if (cell.getParent() == null) {
        return null;
      }

      while (cell.getParent() != null && cell.getParent().isTransparentCollection()) {
        cell = cell.getParent();
      }
      jetbrains.mps.openapi.editor.cells.EditorCell_Collection parent = cell.getParent();
      while (parent != null) {
        if (parent.isSelectable()) {
          while (parent.getParent() != null
              && parent.getParent().isTransparentCollection()
              && parent.getParent().isSelectable()) {
            parent = parent.getParent();
          }
          return (EditorCell) parent;
        }
        parent = parent.getParent();
      }
      return null;
    }
  @Override
  public void execute(EditorContext context) {
    LOG.assertInCommand();
    EditorComponent editorComponent = (EditorComponent) context.getEditorComponent();
    EditorCell selectedCell = editorComponent.getSelectedCell();
    SNode anchorNode = selectedCell.getSNode();

    PasteNodeData pasteNodeData =
        CopyPasteUtil.getPasteNodeDataFromClipboard(anchorNode.getModel());
    if (pasteNodeData == null || pasteNodeData.getNodes().isEmpty()) {
      pasteNodeData =
          CopyPasteUtil.getConvertedFromClipboard(
              anchorNode.getModel(), context.getOperationContext().getProject());
      if (pasteNodeData == null) return;
    }
    List<SNode> pasteNodes = pasteNodeData.getNodes();
    Set<SReference> requireResolveReferences = pasteNodeData.getRequireResolveReferences();

    new NodePaster(pasteNodes).pasteRelative(anchorNode, myPastePlaceHint);
    ResolverComponent.getInstance()
        .resolveScopesOnly(requireResolveReferences, context.getOperationContext());

    // set selection
    editorComponent.flushEvents();
    EditorCell nodeCell = editorComponent.findNodeCell(pasteNodes.get(0));
    if (nodeCell == null) return; // after 'set reference'?
    EditorCell_Label labelCell =
        CellFinderUtil.findChildByClass(nodeCell, EditorCell_Label.class, true);

    if (labelCell != null) {
      editorComponent.changeSelection(labelCell);
    }

    if (pasteNodes.size() == 1) {
      editorComponent.pushSelection(nodeCell);
    } else {
      SelectionManager selectionManager = editorComponent.getSelectionManager();
      selectionManager.pushSelection(
          selectionManager.createRangeSelection(
              pasteNodes.get(0), pasteNodes.get(pasteNodes.size() - 1)));
    }
  }
Esempio n. 7
0
 private EditorCell findTarget(SelectionManager selectionManager) {
   Selection selection = selectionManager.getSelection();
   if (selection == null) {
     return null;
   }
   EditorCell cell = selection.getSelectedCells().get(0);
   while (cell.getParent() != null) {
     cell = (EditorCell) cell.getParent();
   }
   if (cell instanceof EditorCell_Collection) {
     return cell.findChild(
         myHome ? CellFinders.FIRST_SELECTABLE_LEAF : CellFinders.LAST_SELECTABLE_LEAF);
   }
   return cell;
 }
Esempio n. 8
0
 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);
 }
Esempio n. 9
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);
 }
Esempio n. 10
0
 public void execute(jetbrains.mps.openapi.editor.EditorContext context) {
   SelectionManager selectionManager =
       ((EditorComponent) context.getEditorComponent()).getSelectionManager();
   selectionManager.setSelection(findTarget(selectionManager));
   selectionManager.getSelection().ensureVisible();
 }