Search in sources :

Example 61 with Position

use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.

the class TextEditingTarget method onGoToEndOfCurrentScope.

@Handler
void onGoToEndOfCurrentScope() {
    docDisplay_.focus();
    Scope scope = docDisplay_.getCurrentScope();
    if (scope != null) {
        Position end = scope.getEnd();
        if (end != null) {
            Position position = Position.create(end.getRow(), Math.max(0, end.getColumn() - 1));
            docDisplay_.setCursorPosition(position);
        }
    }
}
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)

Example 62 with Position

use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.

the class NotebookQueueState method getNotebookExecRange.

private NotebookExecRange getNotebookExecRange(Scope scope, Range range) {
    // convert range into character offsets
    Position startPos = range.getStart();
    Position endPos = range.getEnd();
    int start = 0;
    int end = 0;
    int pos = 0;
    for (int row = scope.getPreamble().getRow(); row < scope.getEnd().getRow(); row++) {
        String line = docDisplay_.getLine(row);
        for (int col = 0; col <= line.length(); col++) {
            if (startPos.getRow() == row && startPos.getColumn() == col) {
                start = pos;
            } else if (endPos.getRow() == row && endPos.getColumn() == col) {
                end = pos;
                break;
            }
            pos++;
        }
    }
    // the newline)
    if (end == 0)
        end = pos - 1;
    return NotebookExecRange.create(start, end);
}
Also used : Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)

Example 63 with Position

use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.

the class SetupChunkOptionsPopupPanel method findOptsChunk.

private Range findOptsChunk() {
    TokenIterator iterator = display_.createTokenIterator(position_);
    while (true) {
        Token token = iterator.stepForward();
        if (token == null)
            break;
        if (token.hasType("codeend"))
            break;
        Position startPos = iterator.getCurrentTokenPosition();
        if (!token.getValue().equals("opts_chunk"))
            continue;
        Position knitrPrefixPos = findKnitrPrefix(iterator.clone());
        if (knitrPrefixPos != null)
            startPos = knitrPrefixPos;
        token = iterator.stepForward();
        if (!token.getValue().equals("$"))
            continue;
        token = iterator.stepForward();
        if (!token.getValue().equals("set"))
            continue;
        token = iterator.stepForward();
        if (!token.getValue().equals("("))
            continue;
        if (!iterator.fwdToMatchingToken())
            continue;
        token = iterator.stepForward();
        Position endPos = iterator.getCurrentTokenPosition();
        return Range.fromPoints(startPos, endPos);
    }
    return null;
}
Also used : TokenIterator(org.rstudio.studio.client.workbench.views.source.editors.text.ace.TokenIterator) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) Token(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Token)

Example 64 with Position

use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position in project rstudio by rstudio.

the class TextEditingTargetNotebook method onScopeTreeReady.

@Override
public void onScopeTreeReady(ScopeTreeReadyEvent event) {
    Scope thisScope = event.getCurrentScope();
    // initialization 
    if (lastStart_ == null && lastEnd_ == null) {
        if (thisScope != null) {
            lastStart_ = Position.create(thisScope.getBodyStart());
            lastEnd_ = Position.create(thisScope.getEnd());
        }
        return;
    }
    // avoid it)
    if (thisScope != null) {
        Position thisStart = thisScope.getBodyStart();
        Position thisEnd = thisScope.getEnd();
        if (((lastStart_ == null && thisStart == null) || (lastStart_ != null && lastStart_.compareTo(thisStart) == 0)) && ((lastEnd_ == null && thisEnd == null) || (lastEnd_ != null && lastEnd_.compareTo(thisEnd) == 0))) {
            return;
        }
        lastStart_ = Position.create(thisScope.getBodyStart());
        lastEnd_ = Position.create(thisScope.getEnd());
    } else {
        lastStart_ = null;
        lastEnd_ = null;
    }
    for (ChunkOutputUi output : outputs_.values()) {
        Scope scope = output.getScope();
        // remove the widget
        if (scope == null || !scope.isChunk() || scope.getBodyStart() == null || scope.getEnd() == null || scope.getEnd().getRow() - output.getCurrentRow() > 1) {
            events_.fireEvent(new ChunkChangeEvent(docUpdateSentinel_.getId(), output.getChunkId(), "", 0, ChunkChangeEvent.CHANGE_REMOVE));
        }
    }
}
Also used : Scope(org.rstudio.studio.client.workbench.views.source.editors.text.Scope) ChunkChangeEvent(org.rstudio.studio.client.workbench.views.source.events.ChunkChangeEvent) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)

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