use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.
the class RoxygenHelper method insertRoxygenTemplate.
private void insertRoxygenTemplate(String name, JsArrayString argNames, JsArrayString argTypes, String argTagName, String type, Position position) {
String roxygenParams = argsToExampleRoxygen(argNames, argTypes, argTagName);
// if there were one or more arguments.
if (argNames.length() != 0)
roxygenParams += "\n#'\n";
String block = "#' Title\n" + "#'\n" + roxygenParams + "#' @return\n" + "#' @export\n" + "#'\n" + "#' @examples\n";
Position insertionPosition = Position.create(position.getRow(), 0);
editor_.insertCode(insertionPosition, block);
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.
the class MathJax method beginCursorMonitoring.
private void beginCursorMonitoring() {
endCursorMonitoring();
cursorChangedHandler_ = docDisplay_.addCursorChangedHandler(new CursorChangedHandler() {
@Override
public void onCursorChanged(CursorChangedEvent event) {
Position position = event.getPosition();
if (anchor_ == null || !anchor_.getRange().contains(position))
endRender();
}
});
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.
the class MathJaxUtil method findLatexChunks.
public static List<Range> findLatexChunks(DocDisplay docDisplay) {
docDisplay.tokenizeDocument();
List<Range> ranges = new ArrayList<Range>();
Position startPos = null;
for (int i = 0, n = docDisplay.getRowCount(); i < n; i++) {
Position pos = Position.create(i, 0);
Token token = docDisplay.getTokenAt(Position.create(i, 0));
if (token == null)
continue;
if (token.hasAllTypes("latex", "begin") && token.getValue().equals("$$")) {
startPos = pos;
// get the length of this line to see if it could be an inline
// LaTeX chunk (e.g. $$ x = y $$)
int length = docDisplay.getLength(i);
if (length < 5)
continue;
// get the last token on the row; if it's a LaTeX end token then
// consider the row to be an inline LaTeX chunk
Token endLineToken = docDisplay.getTokenAt(Position.create(i, docDisplay.getLength(i)));
if (endLineToken != null && endLineToken.hasAllTypes("latex", "end")) {
ranges.add(Range.fromPoints(startPos, Position.create(i, length)));
}
continue;
}
if (token.hasAllTypes("latex", "end") && token.getValue().equals("$$")) {
ranges.add(Range.fromPoints(startPos, Position.create(i, 2)));
continue;
}
}
return ranges;
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.
the class DiagnosticsBackgroundPopup method start.
public void start() {
isRunning_ = true;
stopRequested_ = false;
if (handler_ != null) {
handler_.removeHandler();
handler_ = null;
}
handler_ = Event.addNativePreviewHandler(new NativePreviewHandler() {
@Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
if (event.getTypeInt() == Event.ONMOUSEMOVE) {
movedMouseMostRecently_ = true;
Element target = Element.as(event.getNativeEvent().getEventTarget());
if (target.hasClassName("ace_gutter-cell")) {
lastMouseCoords_ = null;
hidePopup();
return;
}
lastMouseCoords_ = ScreenCoordinates.create(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
if (activeMarker_ != null && !activeMarker_.getRange().containsRightExclusive(editor_.toDocumentPosition(lastMouseCoords_))) {
hidePopup();
}
} else {
movedMouseMostRecently_ = false;
}
}
});
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
@Override
public boolean execute() {
if (stopRequested_)
return stopExecution();
// restarted later)
if (!docDisplay_.isFocused())
return stopExecution();
long currentTime = System.currentTimeMillis();
long lastModifiedTime = docDisplay_.getLastModifiedTime();
long lastCursorChangedTime = docDisplay_.getLastCursorChangedTime();
// cursor was moved recently, then bail
if ((currentTime - lastModifiedTime) < 500)
return completeExecution();
if ((currentTime - lastCursorChangedTime) < 500)
return completeExecution();
Markers markers = editor_.getSession().getMarkers(true);
Position currentPos;
if (movedMouseMostRecently_) {
if (lastMouseCoords_ == null)
return completeExecution();
currentPos = editor_.toDocumentPosition(lastMouseCoords_);
} else {
currentPos = docDisplay_.getCursorPosition();
}
int[] keys = markers.getIds();
for (int i = 0; i < keys.length; i++) {
Marker marker = markers.get(keys[i]);
if (marker.getRange().containsRightExclusive(currentPos)) {
displayMarkerDiagnostics(marker);
return completeExecution();
}
}
return completeExecution();
}
}, 500);
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.
the class CompletionRequester method addFunctionArgumentCompletions.
private void addFunctionArgumentCompletions(String token, ArrayList<QualifiedName> completions) {
AceEditor editor = (AceEditor) docDisplay_;
if (editor != null) {
Position cursorPosition = editor.getSession().getSelection().getCursor();
CodeModel codeModel = editor.getSession().getMode().getRCodeModel();
// Try to see if we can find a function name
TokenCursor cursor = codeModel.getTokenCursor();
// NOTE: This can fail if the document is empty
if (!cursor.moveToPosition(cursorPosition))
return;
String tokenLower = token.toLowerCase();
if (cursor.currentValue() == "(" || cursor.findOpeningBracket("(", false)) {
if (cursor.moveToPreviousToken()) {
// Check to see if this really is the name of a function
JsArray<ScopeFunction> functionsInScope = codeModel.getAllFunctionScopes();
String tokenName = cursor.currentValue();
for (int i = 0; i < functionsInScope.length(); i++) {
ScopeFunction rFunction = functionsInScope.get(i);
String fnName = rFunction.getFunctionName();
if (tokenName == fnName) {
JsArrayString args = rFunction.getFunctionArgs();
for (int j = 0; j < args.length(); j++) {
String arg = args.get(j);
if (arg.toLowerCase().startsWith(tokenLower))
completions.add(new QualifiedName(args.get(j) + " = ", fnName, false, RCompletionType.CONTEXT));
}
}
}
}
}
}
}
Aggregations