Example #1
0
    private EditorCell findTarget(SelectionManager selectionManager) {
      Selection selection = selectionManager.getSelection();
      if (selection == null) {
        return null;
      }

      jetbrains.mps.openapi.editor.cells.EditorCell cell = selection.getSelectedCells().get(0);
      if (cell instanceof EditorCell_Label && !((EditorCell_Label) cell).isEverythingSelected()) {
        return (EditorCell) cell;
      }

      if (cell.getParent() == null) {
        return null;
      }

      while (cell.getParent() != null && cell.getParent().isTransparentCollection()) {
        cell = cell.getParent();
      }
      jetbrains.mps.openapi.editor.cells.EditorCell_Collection parent = cell.getParent();
      while (parent != null) {
        if (parent.isSelectable()) {
          while (parent.getParent() != null
              && parent.getParent().isTransparentCollection()
              && parent.getParent().isSelectable()) {
            parent = parent.getParent();
          }
          return (EditorCell) parent;
        }
        parent = parent.getParent();
      }
      return null;
    }
Example #2
0
    private EditorCell getCommonSelectableAncestor(
        jetbrains.mps.openapi.editor.cells.EditorCell first,
        jetbrains.mps.openapi.editor.cells.EditorCell... cells) {
      jetbrains.mps.openapi.editor.cells.EditorCell_Collection result =
          first instanceof jetbrains.mps.openapi.editor.cells.EditorCell_Collection
              ? (jetbrains.mps.openapi.editor.cells.EditorCell_Collection) first
              : first.getParent();
      while (result != null) {
        if (result.isSelectable()) {
          boolean common = true;
          for (jetbrains.mps.openapi.editor.cells.EditorCell cell : cells) {
            if (!result.isAncestorOf(cell) && result != cell) {
              common = false;
              break;
            }
          }
          if (common) return (EditorCell) result;
        }

        result = result.getParent();
      }
      return null;
    }
Example #3
0
 private static void navigatePage(
     jetbrains.mps.openapi.editor.EditorContext context, boolean isDown) {
   EditorComponent editor = (EditorComponent) context.getEditorComponent();
   jetbrains.mps.openapi.editor.cells.EditorCell selection = editor.getSelectedCell();
   Rectangle rect = editor.getVisibleRect();
   int height = (int) rect.getHeight();
   height = isDown ? height : -height;
   int caretX = selection.getCaretX();
   int y = selection.getY() + (selection.getHeight() / 2);
   int newY = y + height;
   jetbrains.mps.openapi.editor.cells.EditorCell target = editor.findCellWeak(caretX, newY);
   if (target == null) {
     target =
         isDown
             ? editor.myRootCell.findChild(CellFinders.LAST_SELECTABLE_LEAF)
             : editor.myRootCell.findChild(CellFinders.FIRST_SELECTABLE_LEAF);
     editor.changeSelection(target);
   } else {
     target.setCaretX(caretX);
     editor.changeSelection(target);
   }
 }