Search in sources :

Example 31 with Position

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

Example 32 with Position

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

Example 33 with Position

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

Example 34 with Position

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

Example 35 with Position

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));
                        }
                    }
                }
            }
        }
    }
}
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) CodeModel(org.rstudio.studio.client.workbench.views.source.editors.text.ace.CodeModel) AceEditor(org.rstudio.studio.client.workbench.views.source.editors.text.AceEditor) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) ScopeFunction(org.rstudio.studio.client.workbench.views.source.editors.text.ScopeFunction)

Aggregations

Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)64 InputEditorPosition (org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorPosition)20 JsArrayString (com.google.gwt.core.client.JsArrayString)16 Breakpoint (org.rstudio.studio.client.common.debugging.model.Breakpoint)11 Range (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)11 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)7 FileChangeHandler (org.rstudio.studio.client.workbench.views.files.events.FileChangeHandler)7 TokenCursor (org.rstudio.studio.client.workbench.views.source.editors.text.ace.TokenCursor)7 SourcePosition (org.rstudio.studio.client.workbench.views.source.model.SourcePosition)7 Handler (org.rstudio.core.client.command.Handler)6 EnsureHeightHandler (org.rstudio.core.client.events.EnsureHeightHandler)6 EnsureVisibleHandler (org.rstudio.core.client.events.EnsureVisibleHandler)6 ChangeFontSizeHandler (org.rstudio.studio.client.application.events.ChangeFontSizeHandler)6 ServerError (org.rstudio.studio.client.server.ServerError)6 AceEditor (org.rstudio.studio.client.workbench.views.source.editors.text.AceEditor)6 Token (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Token)6 HideMessageHandler (org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBar.HideMessageHandler)6 RecordNavigationPositionHandler (org.rstudio.studio.client.workbench.views.source.events.RecordNavigationPositionHandler)6 InputEditorLineWithCursorPosition (org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorLineWithCursorPosition)4 CodeModel (org.rstudio.studio.client.workbench.views.source.editors.text.ace.CodeModel)4