Esempio n. 1
0
 @Override
 protected boolean suppressDelete(CellActionType type) {
   if (!super.suppressDelete(type)) {
     return false;
   }
   EditorCell_Label label = getEditorCellLabel();
   if (label.getText().length() == 0) {
     return false;
   }
   if (label instanceof EditorCell_Constant || label instanceof EditorCell_Property) {
     return label.isEditable()
         || CellFinderUtil.findLastSelectableLeaf(APICellAdapter.getContainingBigCell(label))
             != label;
   }
   return true;
 }
Esempio n. 2
0
  private boolean processSideDeletes(CellActionType type) {
    // TODO: review this logic - it was originally copied from EditorComponentKeyboardHandler
    final EditorCell selectedCell = getEditorCell();
    if (type == CellActionType.DELETE
        && APICellAdapter.isLastPositionInBigCell(selectedCell)
        && !APICellAdapter.isFirstPositionInBigCell(selectedCell)) {
      final EditorCell target;
      EditorCell bigCellNextSibling =
          CellTraversalUtil.getNextSibling(APICellAdapter.getContainingBigCell(selectedCell));
      if (bigCellNextSibling != null) {
        target = bigCellNextSibling;
      } else {
        EditorCell nextSibling =
            CellTraversalUtil.getNextSibling(APICellAdapter.getContainingBigCell(selectedCell));
        if (nextSibling != null) {
          target = nextSibling;
        } else {
          target =
              CellTraversalUtil.getNextLeaf(
                  selectedCell, jetbrains.mps.openapi.editor.cells.CellConditions.SELECTABLE);
        }
      }

      if (target == null
          || ModelAccess.instance()
              .runReadAction(
                  new Computable<Boolean>() {
                    @Override
                    public Boolean compute() {
                      return jetbrains.mps.util.SNodeOperations.isAncestor(
                          target.getSNode(), selectedCell.getSNode());
                    }
                  })) return false;

      return getEditorComponent().getActionHandler().executeAction(target, type);
    }

    if (type == CellActionType.BACKSPACE
        && APICellAdapter.isFirstPositionInBigCell(selectedCell)
        && !APICellAdapter.isLastPositionInBigCell(selectedCell)) {
      final EditorCell target;
      EditorCell bigCellPrevSibling =
          CellTraversalUtil.getPrevSibling(APICellAdapter.getContainingBigCell(selectedCell));
      if (bigCellPrevSibling != null) {
        target = bigCellPrevSibling;
      } else {
        EditorCell prevSibling = CellTraversalUtil.getPrevSibling(selectedCell);
        if (prevSibling != null) {
          target = prevSibling;
        } else {
          target =
              CellTraversalUtil.getPrevLeaf(
                  selectedCell, jetbrains.mps.openapi.editor.cells.CellConditions.SELECTABLE);
        }
      }

      if (target == null || ReadOnlyUtil.isCellReadOnly(target)) return false;
      /*
        Was commented out (again) to let some of our unit-tests be green.
        in particular - pressing BackSpace at this situation:
          <code>
            int a = 1;
            --|a;
          <code>
        where "|" is a position of cursor;
      if (ModelAccess.instance().runReadAction(new Computable<Boolean>() {
        public Boolean compute() {
          return jetbrains.mps.util.SNodeOperations.isAncestor(target.getSNode(), selectedCell.getSNode());
        }
      })) return false;
        */
      return getEditorComponent().getActionHandler().executeAction(target, type);
    }
    return false;
  }