Exemplo n.º 1
0
  private void navigate(SourcePosition srcPosition, boolean addToHistory, boolean highlightLine) {
    // set cursor to function line
    Position position = Position.create(srcPosition.getRow(), srcPosition.getColumn());
    setCursorPosition(position);

    // skip whitespace if necessary
    if (srcPosition.getColumn() == 0) {
      int curRow = getSession().getSelection().getCursor().getRow();
      String line = getSession().getLine(curRow);
      int funStart = line.indexOf(line.trim());
      position = Position.create(curRow, funStart);
      setCursorPosition(position);
    }

    // scroll as necessary
    if (srcPosition.getScrollPosition() != -1) scrollToY(srcPosition.getScrollPosition());
    else moveCursorNearTop();

    // set focus
    focus();

    if (highlightLine) applyLineHighlight(position.getRow());

    // add to navigation history if requested and our current mode
    // supports history navigation
    if (addToHistory) fireRecordNavigationPosition(position);
  }
Exemplo n.º 2
0
 public AnchoredSelection createAnchoredSelection(Position startPos, Position endPos) {
   Anchor start =
       Anchor.createAnchor(getSession().getDocument(), startPos.getRow(), startPos.getColumn());
   Anchor end =
       Anchor.createAnchor(getSession().getDocument(), endPos.getRow(), endPos.getColumn());
   return new AnchoredSelectionImpl(start, end);
 }
Exemplo n.º 3
0
  public Rectangle getPositionBounds(InputEditorPosition position) {
    Renderer renderer = widget_.getEditor().getRenderer();

    Position pos = ((AceInputEditorPosition) position).getValue();

    ScreenCoordinates start = renderer.textToScreenCoordinates(pos.getRow(), pos.getColumn());

    return new Rectangle(
        start.getPageX(),
        start.getPageY(),
        (int) Math.round(renderer.getCharacterWidth()),
        (int) (renderer.getLineHeight() * 0.8));
  }
Exemplo n.º 4
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);
  }
Exemplo n.º 5
0
 @Override
 public SourcePosition findFunctionPositionFromCursor(String functionName) {
   Scope func =
       getSession()
           .getMode()
           .getCodeModel()
           .findFunctionDefinitionFromUsage(getCursorPosition(), functionName);
   if (func != null) {
     Position position = func.getPreamble();
     return SourcePosition.create(position.getRow(), position.getColumn());
   } else {
     return null;
   }
 }
Exemplo n.º 6
0
 private void applyDebugLineHighlight(Position startPos, Position endPos, boolean executing) {
   clearDebugLineHighlight();
   lineDebugMarkerId_ = createRangeHighlightMarker(startPos, endPos, "ace_active_debug_line");
   if (executing) {
     executionLine_ = startPos.getRow();
     widget_.getEditor().getRenderer().addGutterDecoration(executionLine_, "ace_executing-line");
   }
 }
Exemplo 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);
  }
Exemplo n.º 8
0
  private void doSetCode(String code, boolean preserveCursorPosition) {
    // Filter out Escape characters that might have snuck in from an old
    // bug in 0.95. We can choose to remove this when 0.95 ships, hopefully
    // any documents that would be affected by this will be gone by then.
    code = code.replaceAll("\u001B", "");

    final AceEditorNative ed = widget_.getEditor();

    if (preserveCursorPosition) {
      final Position cursorPos;
      final int scrollTop, scrollLeft;

      cursorPos = ed.getSession().getSelection().getCursor();
      scrollTop = ed.getRenderer().getScrollTop();
      scrollLeft = ed.getRenderer().getScrollLeft();

      // Setting the value directly on the document prevents undo/redo
      // stack from being blown away
      widget_.getEditor().getSession().getDocument().setValue(code);

      ed.getSession().getSelection().moveCursorTo(cursorPos.getRow(), cursorPos.getColumn(), false);
      ed.getRenderer().scrollToY(scrollTop);
      ed.getRenderer().scrollToX(scrollLeft);
      Scheduler.get()
          .scheduleDeferred(
              new ScheduledCommand() {
                @Override
                public void execute() {
                  ed.getRenderer().scrollToY(scrollTop);
                  ed.getRenderer().scrollToX(scrollLeft);
                }
              });
    } else {
      ed.getSession().setValue(code);
      ed.getSession().getSelection().moveCursorTo(0, 0, false);
    }
  }
Exemplo n.º 9
0
 public InputEditorSelection getEnd() {
   EditSession session = getSession();
   int rows = session.getLength();
   Position end = Position.create(rows, session.getLine(rows).length());
   return new InputEditorSelection(new AceInputEditorPosition(session, end));
 }
Exemplo n.º 10
0
 public InputEditorSelection getStart() {
   return new InputEditorSelection(
       new AceInputEditorPosition(getSession(), Position.create(0, 0)));
 }
Exemplo n.º 11
0
 public boolean isCursorAtEnd() {
   int lastRow = getRowCount() - 1;
   Position cursorPos = getCursorPosition();
   return cursorPos.compareTo(Position.create(lastRow, getLength(lastRow))) == 0;
 }
Exemplo n.º 12
0
 @Override
 public Anchor createAnchor(Position pos) {
   return Anchor.createAnchor(getSession().getDocument(), pos.getRow(), pos.getColumn());
 }
Exemplo n.º 13
0
 @Override
 public boolean isAtSourceRow(SourcePosition position) {
   Position currPos = getCursorPosition();
   return currPos.getRow() == position.getRow();
 }
Exemplo n.º 14
0
 private Integer createLineHighlightMarker(int line, String style) {
   return createRangeHighlightMarker(
       Position.create(line, 0), Position.create(line + 1, 0), style);
 }
Exemplo n.º 15
0
 private void fireRecordNavigationPosition(Position pos) {
   SourcePosition srcPos = SourcePosition.create(pos.getRow(), pos.getColumn());
   fireEvent(new RecordNavigationPositionEvent(srcPos));
 }
Exemplo n.º 16
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.º 17
0
 @Override
 public Position selectionToPosition(InputEditorPosition pos) {
   // HACK: This cast is gross, InputEditorPosition should just become
   // AceInputEditorPosition
   return Position.create((Integer) pos.getLine(), pos.getPosition());
 }