Exemplo n.º 1
0
  public static EditorCell getSiblingCollectionForInsert(
      @NotNull EditorCell cell, boolean forward) {
    // TODO FIXME rewrite without hasSingleRolesAtLeftBoundary, cleanup ChildrenCollectionFinder
    EditorCell nextLeaf =
        (forward ? APICellAdapter.getNextLeaf(cell) : APICellAdapter.getPrevLeaf(cell));

    if ((APICellAdapter.isBigCell(cell) || APICellAdapter.isLastPositionInBigCell(cell))
        && ((forward ? hasSingleRolesAtRightBoundary(cell) : hasSingleRolesAtLeftBoundary(cell)))
        && nextLeaf != null) {
      // Looking for the next child collection in parents
      return new ChildrenCollectionFinder(nextLeaf, cell, forward, true).find();
    }
    return null;
  }
Exemplo n.º 2
0
  private EditorCell getCellToPasteTo(EditorCell cell) {
    if (cell == null) {
      return cell;
    }
    if (APICellAdapter.isLastPositionInBigCell(cell)) return cell;

    if (cell instanceof EditorCell_Label && cell.getRole() == null) {
      EditorCell result = new ChildrenCollectionFinder(cell, true, false).find();
      if (result != null) {
        return result;
      }
      result = new ChildrenCollectionFinder(cell, false, false).find();
      if (result != null) {
        if (result instanceof EditorCell_Collection) {
          return ((EditorCell_Collection) result).lastCell();
        }
        return result;
      }
    }
    return cell;
  }
Exemplo n.º 3
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;
  }