Пример #1
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()));
 }
Пример #2
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);
  }
Пример #3
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);
  }
Пример #4
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));
  }
Пример #5
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);
 }
Пример #6
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));
 }
Пример #7
0
 @Override
 public Range getSelectionRange() {
   return Range.fromPoints(getSelectionStart(), getSelectionEnd());
 }
Пример #8
0
 public String getCode(Position start, Position end) {
   return getSession().getTextRange(Range.fromPoints(start, end));
 }
Пример #9
0
 private Integer createRangeHighlightMarker(Position start, Position end, String style) {
   Range range = Range.fromPoints(start, end);
   return getSession().addMarker(range, style, "text", false);
 }
Пример #10
0
 public Range getRange() {
   return Range.fromPoints(start_.getPosition(), end_.getPosition());
 }
Пример #11
0
 public void setCursorPosition(Position position) {
   getSession().getSelection().setSelectionRange(Range.fromPoints(position, position));
 }
Пример #12
0
 @Override
 public void unfold(AceFold fold) {
   getSession().unfold(Range.fromPoints(fold.getStart(), fold.getEnd()), false);
 }