Search in sources :

Example 31 with Range

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();
                            }
                        }
                    }
                });
            }
        }
    });
}
Also used : NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) Range(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)

Example 32 with Range

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();
}
Also used : TokenCursor(org.rstudio.studio.client.workbench.views.source.editors.text.ace.TokenCursor) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) JsArrayString(com.google.gwt.core.client.JsArrayString) Range(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)

Example 33 with Range

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);
    }
}
Also used : Range(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) Handler(org.rstudio.core.client.command.Handler) ChangeFontSizeHandler(org.rstudio.studio.client.application.events.ChangeFontSizeHandler) RecordNavigationPositionHandler(org.rstudio.studio.client.workbench.views.source.events.RecordNavigationPositionHandler) EnsureHeightHandler(org.rstudio.core.client.events.EnsureHeightHandler) EnsureVisibleHandler(org.rstudio.core.client.events.EnsureVisibleHandler) HideMessageHandler(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler) FileChangeHandler(org.rstudio.studio.client.workbench.views.files.events.FileChangeHandler)

Example 34 with Range

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;
}
Also used : LintItem(org.rstudio.studio.client.workbench.views.output.lint.model.LintItem) CppDiagnostic(org.rstudio.studio.client.workbench.views.source.model.CppDiagnostic) Range(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)

Example 35 with Range

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");
}
Also used : Range(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)

Aggregations

Range (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)37 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)11 JsArrayString (com.google.gwt.core.client.JsArrayString)7 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)7 Breakpoint (org.rstudio.studio.client.common.debugging.model.Breakpoint)5 Token (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Token)5 ArrayList (java.util.ArrayList)4 AnchoredRange (org.rstudio.studio.client.workbench.views.source.editors.text.ace.AnchoredRange)4 Scope (org.rstudio.studio.client.workbench.views.source.editors.text.Scope)3 JsArray (com.google.gwt.core.client.JsArray)2 Command (com.google.gwt.user.client.Command)2 NativePreviewEvent (com.google.gwt.user.client.Event.NativePreviewEvent)2 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)2 Handler (org.rstudio.core.client.command.Handler)2 EnsureHeightHandler (org.rstudio.core.client.events.EnsureHeightHandler)2 EnsureVisibleHandler (org.rstudio.core.client.events.EnsureVisibleHandler)2 Match (org.rstudio.core.client.regex.Match)2 ChangeFontSizeHandler (org.rstudio.studio.client.application.events.ChangeFontSizeHandler)2 FileChangeHandler (org.rstudio.studio.client.workbench.views.files.events.FileChangeHandler)2 HideMessageHandler (org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler)2