use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.
the class AceEditorWidget method removeMarkersAtCursorPosition.
public void removeMarkersAtCursorPosition() {
// Defer this so other event handling can update anchors etc.
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
Position cursor = editor_.getCursorPosition();
JsArray<AceAnnotation> newAnnotations = JsArray.createArray().cast();
for (int i = 0; i < annotations_.size(); i++) {
AnchoredAceAnnotation annotation = annotations_.get(i);
int markerId = annotation.getMarkerId();
Marker marker = editor_.getSession().getMarker(markerId);
// a previous action.
if (marker == null)
continue;
Range range = marker.getRange();
if (!range.contains(cursor))
newAnnotations.push(annotation.asAceAnnotation());
else
editor_.getSession().removeMarker(markerId);
}
editor_.getSession().setAnnotations(newAnnotations);
editor_.getRenderer().renderMarkers();
}
});
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.
the class TextEditingTarget method onInsertChunk.
private void onInsertChunk(String chunkPlaceholder, int rowOffset, int colOffset) {
String sel = null;
Range selRange = null;
// if currently in a chunk, add a blank line (for padding) and insert
// beneath it
Scope currentChunk = docDisplay_.getCurrentChunk();
if (currentChunk != null) {
// record current selection before manipulating text
sel = docDisplay_.getSelectionValue();
selRange = docDisplay_.getSelectionRange();
docDisplay_.setCursorPosition(currentChunk.getEnd());
docDisplay_.insertCode("\n");
docDisplay_.moveCursorForward(1);
}
Position pos = moveCursorToNextInsertLocation();
InsertChunkInfo insertChunkInfo = docDisplay_.getInsertChunkInfo();
if (insertChunkInfo != null) {
// inject the chunk skeleton
docDisplay_.insertCode(chunkPlaceholder, false);
// if we had text selected, inject it into the chunk
if (!StringUtil.isNullOrEmpty(sel)) {
Position contentPosition = insertChunkInfo.getContentPosition();
Position docContentPos = Position.create(pos.getRow() + contentPosition.getRow(), contentPosition.getColumn());
Position endPos = Position.create(docContentPos.getRow(), docContentPos.getColumn());
// move over newline if selected
if (sel.endsWith("\n"))
endPos.setRow(endPos.getRow() + 1);
docDisplay_.replaceRange(Range.fromPoints(docContentPos, endPos), sel);
docDisplay_.replaceRange(selRange, "");
}
Position cursorPosition = insertChunkInfo.getCursorPosition();
docDisplay_.setCursorPosition(Position.create(pos.getRow() + cursorPosition.getRow() + rowOffset, colOffset));
docDisplay_.focus();
} else {
assert false : "Mode did not have insertChunkInfo available";
}
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.
the class TextEditingTarget method moveCursorToPreviousSectionOrChunk.
private boolean moveCursorToPreviousSectionOrChunk(boolean includeSections) {
ScopeList scopes = new ScopeList(docDisplay_);
Position cursorPos = docDisplay_.getCursorPosition();
int n = scopes.size();
for (int i = n - 1; i >= 0; i--) {
Scope scope = scopes.get(i);
if (!(scope.isChunk() || (includeSections && scope.isSection())))
continue;
if (scope.getPreamble().isBefore(cursorPos)) {
moveCursorToNextPrevSection(scope.getPreamble());
return true;
}
}
return false;
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.
the class TextEditingTarget method moveCursorToNextSectionOrChunk.
private boolean moveCursorToNextSectionOrChunk(boolean includeSections) {
Scope current = docDisplay_.getCurrentScope();
ScopeList scopes = new ScopeList(docDisplay_);
Position cursorPos = docDisplay_.getCursorPosition();
int n = scopes.size();
for (int i = 0; i < n; i++) {
Scope scope = scopes.get(i);
if (!(scope.isChunk() || (scope.isSection() && includeSections)))
continue;
if (scope.equals(current))
continue;
if (scope.getPreamble().isAfter(cursorPos)) {
moveCursorToNextPrevSection(scope.getPreamble());
return true;
}
}
return false;
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.
the class TextEditingTarget method onExecuteCurrentFunction.
@Handler
void onExecuteCurrentFunction() {
docDisplay_.focus();
// HACK: This is just to force the entire function tree to be built.
// It's the easiest way to make sure getCurrentScope() returns
// a Scope with an end.
docDisplay_.getScopeTree();
Scope currentFunction = docDisplay_.getCurrentFunction(false);
// an unclosed function
if (currentFunction == null || currentFunction.getEnd() == null)
return;
Position start = currentFunction.getPreamble();
Position end = currentFunction.getEnd();
codeExecution_.executeRange(Range.fromPoints(start, end));
}
Aggregations