예제 #1
0
  /**
   * We can use this method to determine if we should redispatch insert event to the corresponding
   * child collection below the cell returned from cell.getPrevLeaf() or we should go on and insert
   * prev. child into a collection containing cell itself
   *
   * @return true if we should redispatch insert event to the prev. leaft cell
   */
  private static boolean hasSingleRolesAtLeftBoundary(EditorCell cell) {
    if (!(hasSingleRole(cell))) {
      return false;
    }

    if (isOnLeftBoundary(cell)) {
      final EditorCell_Collection parentCell = cell.getParent();
      if (parentCell != null) {
        final EditorCell prevLeaf = APICellAdapter.getPrevLeaf(cell);
        if (prevLeaf != null) {
          final Wrappers._boolean ancestor = new Wrappers._boolean(false);
          ModelAccess.instance()
              .runReadAction(
                  new Runnable() {
                    public void run() {
                      ancestor.value =
                          SNodeOperations.isAncestor(parentCell.getSNode(), prevLeaf.getSNode());
                    }
                  });
          if (ancestor.value) {
            return true;
          }
        }
        return hasSingleRolesAtLeftBoundary((jetbrains.mps.nodeEditor.cells.EditorCell) parentCell);
      }
    }
    return true;
  }
예제 #2
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;
  }
예제 #3
0
 public static boolean isOnLeftBoundary(EditorCell cell) {
   EditorCell prevLeaf = APICellAdapter.getPrevLeaf(cell);
   return prevLeaf == null || prevLeaf.getSNode() != cell.getSNode();
 }