Search in sources :

Example 16 with Position

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

Example 17 with Position

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

Example 18 with Position

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;
}
Also used : InputEditorPosition(org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorPosition) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint)

Example 19 with Position

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;
}
Also used : InputEditorPosition(org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorPosition) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint)

Example 20 with Position

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));
}
Also used : InputEditorPosition(org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorPosition) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) 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)

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