use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range in project rstudio by rstudio.
the class RCompletionToolTip method onLoad.
@Override
protected void onLoad() {
super.onLoad();
if (nativePreviewReg_ != null) {
nativePreviewReg_.removeHandler();
nativePreviewReg_ = null;
}
nativePreviewReg_ = Event.addNativePreviewHandler(new NativePreviewHandler() {
public void onPreviewNativeEvent(NativePreviewEvent e) {
int eventType = e.getTypeInt();
if (eventType == Event.ONKEYDOWN || eventType == Event.ONMOUSEDOWN) {
// dismiss if we've left our anchor zone
// (defer this so the current key has a chance to
// enter the editor and affect the cursor)
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
Position cursorPos = docDisplay_.getCursorPosition();
if (anchor_ != null) {
Range anchorRange = anchor_.getRange();
if (cursorPos.isBeforeOrEqualTo(anchorRange.getStart()) || cursorPos.isAfterOrEqualTo(anchorRange.getEnd())) {
anchor_.detach();
anchor_ = null;
hide();
}
}
}
});
}
}
});
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range in project rstudio by rstudio.
the class TextEditingTargetRenameHelper method renameVariablesInScope.
private int renameVariablesInScope(Scope scope, Position startPos, String targetValue, String targetType) {
Position endPos = scope.getEnd();
if (endPos == null)
endPos = Position.create(editor_.getSession().getLength(), 0);
TokenCursor cursor = editor_.getSession().getMode().getCodeModel().getTokenCursor();
cursor.moveToPosition(startPos, true);
// Workaround 'moveToPosition' not handling forward searches (yet)
if (cursor.getRow() < startPos.getRow())
if (!cursor.moveToNextToken())
return 0;
// NOTE: The token associated with the current cursor position
// is added last, to ensure that after the 'multi-select' session has
// ended the cursor remains where it started.
Position cursorPos = editor_.getCursorPosition();
do {
// Left brackets push on the stack.
if (cursor.isLeftBracket()) {
// Update state.
if (cursor.valueEquals("(")) {
if (cursor.peekBwd(1).valueEquals("function"))
pushState(STATE_FUNCTION_DEFINITION);
else
pushState(STATE_FUNCTION_CALL);
} else {
pushState(STATE_DEFAULT);
}
// Update protected names for braces.
if (cursor.valueEquals("{"))
pushProtectedNames(cursor.currentPosition(), scope);
continue;
}
// Right brackets pop the stack.
if (cursor.isRightBracket()) {
popState();
if (cursor.valueEquals("}"))
popProtectedNames(cursor.currentPosition());
continue;
}
// Protect a name if it's the target of an assignment in a child scope.
if (cursor.hasType("identifier") && cursor.peekFwd(1).isLeftAssign() && !cursor.peekBwd(1).isExtractionOperator()) {
Scope candidate = editor_.getScopeAtPosition(cursor.currentPosition());
// Skip default arguments for nested functions
if (peekState() == STATE_FUNCTION_DEFINITION && scope != candidate)
continue;
if (cursor.peekFwd(2).valueEquals("function") && !candidate.isTopLevel())
candidate = candidate.getParentScope();
if (candidate != scope) {
addProtectedName(cursor.currentValue());
continue;
}
}
// Bail if we've reached the end of the scope.
if (cursor.currentPosition().isAfterOrEqualTo(endPos))
break;
if (cursor.currentValue().equals(targetValue)) {
// either as assignments, or exist as names to newly defined functions.
if (isProtectedName(cursor.currentValue()))
continue;
// Skip variables following an 'extraction' operator.
if (cursor.peekBwd(1).isExtractionOperator())
continue;
// Skip default arguments for nested functions
Scope candidate = editor_.getScopeAtPosition(cursor.currentPosition());
if (peekState() == STATE_FUNCTION_DEFINITION && scope != candidate)
continue;
// ~~~ ~~~ ~~~
if (peekState() == STATE_FUNCTION_CALL && cursor.nextValue().equals("="))
continue;
// ~~~ ~~~ ~~~
if (peekState() == STATE_FUNCTION_DEFINITION && editor_.getScopeAtPosition(cursor.currentPosition()) != scope) {
String prevValue = cursor.peekBwd(1).getValue();
if (prevValue.equals("(") || prevValue.equals(",") || prevValue.equals("=")) {
continue;
}
}
Range tokenRange = getTokenRange(cursor);
if (!tokenRange.contains(cursorPos))
ranges_.add(tokenRange);
}
} while (cursor.moveToNextToken());
// after exiting 'multi-select' mode)
if (cursor.moveToPosition(cursorPos, true))
ranges_.add(getTokenRange(cursor));
return applyRanges();
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range in project rstudio by rstudio.
the class TextEditingTarget method onFold.
@Handler
void onFold() {
if (useScopeTreeFolding()) {
Range range = Range.fromPoints(docDisplay_.getSelectionStart(), docDisplay_.getSelectionEnd());
if (range.isEmpty()) {
// If no selection, fold the innermost non-anonymous scope
Scope scope = docDisplay_.getCurrentScope();
while (scope != null && scope.isAnon()) scope = scope.getParentScope();
if (scope == null || scope.isTopLevel())
return;
docDisplay_.addFoldFromRow(scope.getFoldStart().getRow());
} else {
// If selection, fold the selection
docDisplay_.addFold(range);
}
} else {
int row = docDisplay_.getSelectionStart().getRow();
docDisplay_.addFoldFromRow(row);
}
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range in project rstudio by rstudio.
the class CppCompletionRequest method asLintArray.
public static JsArray<LintItem> asLintArray(JsArray<CppDiagnostic> diagnostics) {
JsArray<LintItem> lint = JsArray.createArray(diagnostics.length()).cast();
for (int i = 0; i < diagnostics.length(); i++) {
CppDiagnostic d = diagnostics.get(i);
if (d.getPosition() != null) {
Range range = getRangeForDiagnostic(d);
lint.set(i, LintItem.create(range.getStart().getRow(), range.getStart().getColumn(), range.getEnd().getRow(), range.getEnd().getColumn(), d.getMessage(), cppDiagnosticSeverityToLintType(d.getSeverity())));
}
}
return lint;
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range in project rstudio by rstudio.
the class DefaultChunkOptionsPopupPanel method revert.
@Override
protected void revert() {
if (position_ == null)
return;
Range replaceRange = Range.fromPoints(Position.create(position_.getRow(), 0), Position.create(position_.getRow() + 1, 0));
display_.replaceRange(replaceRange, originalLine_ + "\n");
}
Aggregations