Ejemplo n.º 1
0
  public void updateBracesSelection(EditorCell newSelection) {
    clearBracesSelection();

    if (newSelection == null) {
      return;
    }
    EditorCell cellToSelect = null;

    if (getMatchingLabelAndCell(newSelection) != null) {
      cellToSelect = newSelection;
    } else if (newSelection instanceof EditorCell_Label) {
      EditorCell_Label editorCell = (EditorCell_Label) newSelection;
      if (editorCell.getCaretPosition() == 0) {
        jetbrains.mps.openapi.editor.cells.EditorCell cell =
            CellTraversalUtil.getPrevLeaf(editorCell);
        if (cell instanceof EditorCell_Label) {
          EditorCell_Label label = (EditorCell_Label) cell;
          if (label.getWidth() == 0 && editorCell.getLeftInset() == 0) {
            cellToSelect = label;
          }
        }
      } else if (editorCell.getCaretPosition() == editorCell.getText().length()) {
        jetbrains.mps.openapi.editor.cells.EditorCell cell =
            CellTraversalUtil.getNextLeaf(editorCell);
        if (cell instanceof EditorCell_Label) {
          EditorCell_Label label = (EditorCell_Label) cell;
          if (label.getWidth() == 0 && editorCell.getRightInset() == 0) {
            cellToSelect = label;
          }
        }
      }
    }
    if (cellToSelect != null) {
      selectBraces(cellToSelect);
    }
  }
Ejemplo n.º 2
0
 protected boolean isUnderFolded() {
   return CellTraversalUtil.getFoldedParent(this) != null;
 }
Ejemplo 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;
  }