コード例 #1
0
ファイル: AceEditor.java プロジェクト: Rogaven/rstudio
 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);
 }
コード例 #2
0
ファイル: AceEditor.java プロジェクト: Rogaven/rstudio
  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));
  }
コード例 #3
0
ファイル: AceEditor.java プロジェクト: Rogaven/rstudio
  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));
  }
コード例 #4
0
ファイル: AceEditor.java プロジェクト: Rogaven/rstudio
 @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;
   }
 }
コード例 #5
0
ファイル: AceEditor.java プロジェクト: Rogaven/rstudio
  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);
    }
  }
コード例 #6
0
ファイル: AceEditor.java プロジェクト: Rogaven/rstudio
 @Override
 public Anchor createAnchor(Position pos) {
   return Anchor.createAnchor(getSession().getDocument(), pos.getRow(), pos.getColumn());
 }
コード例 #7
0
ファイル: AceEditor.java プロジェクト: Rogaven/rstudio
 private void fireRecordNavigationPosition(Position pos) {
   SourcePosition srcPos = SourcePosition.create(pos.getRow(), pos.getColumn());
   fireEvent(new RecordNavigationPositionEvent(srcPos));
 }