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()); }
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); }
@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; } }
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)); }
public int getSelectionOffset(boolean start) { Range range = getSession().getSelection().getRange(); if (start) return range.getStart().getColumn(); else return range.getEnd().getColumn(); }
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)); }
public InputEditorSelection getSelection() { Range selection = getSession().getSelection().getRange(); return new InputEditorSelection( new AceInputEditorPosition(getSession(), selection.getStart()), new AceInputEditorPosition(getSession(), selection.getEnd())); }