Esempio n. 1
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);
 }
Esempio n. 2
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);
  }
Esempio n. 3
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");
   }
 }
Esempio n. 4
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));
  }
Esempio 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;
   }
 }
Esempio n. 6
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));
  }
Esempio n. 7
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);
    }
  }
Esempio n. 8
0
 @Override
 public Anchor createAnchor(Position pos) {
   return Anchor.createAnchor(getSession().getDocument(), pos.getRow(), pos.getColumn());
 }
Esempio n. 9
0
 private void fireRecordNavigationPosition(Position pos) {
   SourcePosition srcPos = SourcePosition.create(pos.getRow(), pos.getColumn());
   fireEvent(new RecordNavigationPositionEvent(srcPos));
 }
Esempio n. 10
0
 @Override
 public boolean isAtSourceRow(SourcePosition position) {
   Position currPos = getCursorPosition();
   return currPos.getRow() == position.getRow();
 }