Example #1
0
  private boolean processSideDeletes(CellActionType type) {
    // TODO: review this logic - it was originally copied from EditorComponentKeyboardHandler
    final EditorCell selectedCell = getEditorCell();
    if (type == CellActionType.DELETE
        && selectedCell.isLastPositionInBigCell()
        && !selectedCell.isFirstPositionInBigCell()) {
      final EditorCell target;
      if (selectedCell.isLastPositionInBigCell()
          && selectedCell.getContainingBigCell().getNextSibling() != null) {
        target = selectedCell.getContainingBigCell().getNextSibling();
      } else if (selectedCell.getNextSibling() != null) {
        target = selectedCell.getNextSibling();
      } else {
        target = selectedCell.getNextLeaf(CellConditions.SELECTABLE);
      }

      if (target == null
          || ModelAccess.instance()
              .runReadAction(
                  new Computable<Boolean>() {
                    public Boolean compute() {
                      return target.getSNode().isAncestorOf(selectedCell.getSNode());
                    }
                  })) return false;

      return target.executeAction(CellActionType.DELETE);
    }

    if (type == CellActionType.BACKSPACE
        && selectedCell.isFirstPositionInBigCell()
        && !selectedCell.isLastPositionInBigCell()) {
      final EditorCell target;
      if (selectedCell.isFirstPositionInBigCell()
          && selectedCell.getContainingBigCell().getPrevSibling() != null) {
        target = selectedCell.getContainingBigCell().getPrevSibling();
      } else if (selectedCell.getPrevSibling() != null) {
        target = selectedCell.getPrevSibling();
      } else {
        target = selectedCell.getPrevLeaf(CellConditions.SELECTABLE);
      }

      if (target == null) return false;
      /*
      if (ModelAccess.instance().runReadAction(new Computable<Boolean>() {
        public Boolean compute() {
          return target.getSNode().isAncestorOf(selectedCell.getSNode());
        }
      })) return false;
      */
      return target.executeAction(CellActionType.DELETE);
    }
    return false;
  }
Example #2
0
  private EditorCell getCellToPasteTo(EditorCell cell) {
    if (cell == null) {
      return cell;
    }
    if (cell.isLastPositionInBigCell()) 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 result.getLastChild();
        }
        return result;
      }
    }
    return cell;
  }