Exemplo n.º 1
0
 public Rectangle getCursorBounds() {
   Range range = getSession().getSelection().getRange();
   Renderer renderer = widget_.getEditor().getRenderer();
   ScreenCoordinates start =
       renderer.textToScreenCoordinates(range.getStart().getRow(), range.getStart().getColumn());
   ScreenCoordinates end =
       renderer.textToScreenCoordinates(range.getEnd().getRow(), range.getEnd().getColumn());
   return new Rectangle(
       start.getPageX(),
       start.getPageY(),
       end.getPageX() - start.getPageX(),
       renderer.getLineHeight());
 }
Exemplo n.º 2
0
    public boolean shouldComplete(NativeEvent event) {
      // Never complete if there's an active selection
      Range range = getSession().getSelection().getRange();
      if (!range.isEmpty()) return false;

      // Don't consider Tab to be a completion if we're at the start of a
      // line (e.g. only zero or more whitespace characters between the
      // beginning of the line and the cursor)

      if (event != null && event.getKeyCode() != KeyCodes.KEY_TAB) return true;

      int col = range.getStart().getColumn();
      if (col == 0) return false;

      String row = getSession().getLine(range.getStart().getRow());
      return row.substring(0, col).trim().length() != 0;
    }
Exemplo n.º 3
0
  private void indentPastedRange(Range range) {
    if (fileType_ == null
        || !fileType_.canAutoIndent()
        || !RStudioGinjector.INSTANCE.getUIPrefs().reindentOnPaste().getValue()) {
      return;
    }

    String firstLinePrefix =
        getSession()
            .getTextRange(
                Range.fromPoints(Position.create(range.getStart().getRow(), 0), range.getStart()));

    if (firstLinePrefix.trim().length() != 0) {
      Position newStart = Position.create(range.getStart().getRow() + 1, 0);
      if (newStart.compareTo(range.getEnd()) >= 0) return;

      range = Range.fromPoints(newStart, range.getEnd());
    }

    getSession().reindent(range);
  }
Exemplo n.º 4
0
  @Override
  public InputEditorSelection search(
      String needle,
      boolean backwards,
      boolean wrap,
      boolean caseSensitive,
      boolean wholeWord,
      Position start,
      Range range,
      boolean regexpMode) {
    Search search =
        Search.create(needle, backwards, wrap, caseSensitive, wholeWord, start, range, regexpMode);

    Range resultRange = search.find(getSession());
    if (resultRange != null) {
      return createSelection(resultRange.getStart(), resultRange.getEnd());
    } else {
      return null;
    }
  }
Exemplo n.º 5
0
  public void fitSelectionToLines(boolean expand) {
    Range range = getSession().getSelection().getRange();
    Position start = range.getStart();
    Position newStart = start;

    if (start.getColumn() > 0) {
      if (expand) {
        newStart = Position.create(start.getRow(), 0);
      } else {
        String firstLine = getSession().getLine(start.getRow());
        if (firstLine.substring(0, start.getColumn()).trim().length() == 0)
          newStart = Position.create(start.getRow(), 0);
      }
    }

    Position end = range.getEnd();
    Position newEnd = end;
    if (expand) {
      int endRow = end.getRow();
      if (endRow == newStart.getRow() || end.getColumn() > 0) {
        // If selection ends at the start of a line, keep the selection
        // there--unless that means less than one line will be selected
        // in total.
        newEnd = Position.create(endRow, getSession().getLine(endRow).length());
      }
    } else {
      while (newEnd.getRow() != newStart.getRow()) {
        String line = getSession().getLine(newEnd.getRow());
        if (line.substring(0, newEnd.getColumn()).trim().length() != 0) break;

        int prevRow = newEnd.getRow() - 1;
        int len = getSession().getLine(prevRow).length();
        newEnd = Position.create(prevRow, len);
      }
    }

    getSession().getSelection().setSelectionRange(Range.fromPoints(newStart, newEnd));
  }
Exemplo n.º 6
0
 public int getSelectionOffset(boolean start) {
   Range range = getSession().getSelection().getRange();
   if (start) return range.getStart().getColumn();
   else return range.getEnd().getColumn();
 }
Exemplo n.º 7
0
 public void replaceSelection(String code) {
   Range selRange = getSession().getSelection().getRange();
   Position position = getSession().replace(selRange, code);
   Range range = Range.fromPoints(selRange.getStart(), position);
   getSession().getSelection().setSelectionRange(range);
 }
Exemplo n.º 8
0
 public void collapseSelection(boolean collapseToStart) {
   Selection selection = getSession().getSelection();
   Range rng = selection.getRange();
   Position pos = collapseToStart ? rng.getStart() : rng.getEnd();
   selection.setSelectionRange(Range.fromPoints(pos, pos));
 }
Exemplo n.º 9
0
 public InputEditorSelection getSelection() {
   Range selection = getSession().getSelection().getRange();
   return new InputEditorSelection(
       new AceInputEditorPosition(getSession(), selection.getStart()),
       new AceInputEditorPosition(getSession(), selection.getEnd()));
 }