Ejemplo 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());
 }
Ejemplo n.º 2
0
 public void setSelection(InputEditorSelection selection) {
   AceInputEditorPosition start = (AceInputEditorPosition) selection.getStart();
   AceInputEditorPosition end = (AceInputEditorPosition) selection.getEnd();
   getSession()
       .getSelection()
       .setSelectionRange(Range.fromPoints(start.getValue(), end.getValue()));
 }
Ejemplo n.º 3
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;
    }
Ejemplo 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;
    }
  }
Ejemplo 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));
  }
Ejemplo n.º 6
0
  public void replaceCode(String code) {
    int endRow, endCol;

    endRow = getSession().getLength() - 1;
    if (endRow < 0) {
      endRow = 0;
      endCol = 0;
    } else {
      endCol = getSession().getLine(endRow).length();
    }

    Range range = Range.fromPoints(Position.create(0, 0), Position.create(endRow, endCol));
    getSession().replace(range, code);
  }
Ejemplo n.º 7
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);
  }
Ejemplo n.º 8
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);
 }
Ejemplo n.º 9
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));
 }
Ejemplo n.º 10
0
 public void setCursorPosition(Position position) {
   getSession().getSelection().setSelectionRange(Range.fromPoints(position, position));
 }
Ejemplo n.º 11
0
 public InputEditorSelection getSelection() {
   Range selection = getSession().getSelection().getRange();
   return new InputEditorSelection(
       new AceInputEditorPosition(getSession(), selection.getStart()),
       new AceInputEditorPosition(getSession(), selection.getEnd()));
 }
Ejemplo n.º 12
0
 public String getCode(Position start, Position end) {
   return getSession().getTextRange(Range.fromPoints(start, end));
 }
Ejemplo n.º 13
0
 private Integer createRangeHighlightMarker(Position start, Position end, String style) {
   Range range = Range.fromPoints(start, end);
   return getSession().addMarker(range, style, "text", false);
 }
Ejemplo n.º 14
0
 public Range getRange() {
   return Range.fromPoints(start_.getPosition(), end_.getPosition());
 }
Ejemplo n.º 15
0
 @Override
 public Range getSelectionRange() {
   return Range.fromPoints(getSelectionStart(), getSelectionEnd());
 }
Ejemplo n.º 16
0
 public int getSelectionOffset(boolean start) {
   Range range = getSession().getSelection().getRange();
   if (start) return range.getStart().getColumn();
   else return range.getEnd().getColumn();
 }
Ejemplo n.º 17
0
 @Override
 public void unfold(AceFold fold) {
   getSession().unfold(Range.fromPoints(fold.getStart(), fold.getEnd()), false);
 }