Search in sources :

Example 1 with DocDisplay

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

the class ChunkContextUi method switchChunk.

@Override
public void switchChunk(String chunkType) {
    if (chunk_ != null) {
        DocDisplay docDisplay = target_.getDocDisplay();
        Position start = chunk_.getPreamble();
        Position end = chunk_.getEnd();
        String chunkText = docDisplay.getTextForRange(Range.fromPoints(start, end));
        JsArrayString chunkLines = StringUtil.split(chunkText, "\n");
        if (chunkLines.length() > 0) {
            String firstLine = chunkLines.get(0);
            Position linedEnd = Position.create(start.getRow(), firstLine.length());
            String newFirstLine = firstLine.replaceFirst("[, ]*engine='[a-zA-Z]+'", "");
            newFirstLine = newFirstLine.replaceFirst("{[a-zA-Z]+", "{" + chunkType);
            docDisplay.replaceRange(Range.fromPoints(start, linedEnd), newFirstLine);
            target_.getNotebook().clearChunkOutput(chunk_);
        }
    }
}
Also used : Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) DocDisplay(org.rstudio.studio.client.workbench.views.source.editors.text.DocDisplay) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 2 with DocDisplay

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

the class Source method onGetEditorContext.

@Override
public void onGetEditorContext(GetEditorContextEvent event) {
    GetEditorContextEvent.Data data = event.getData();
    int type = data.getType();
    if (type == GetEditorContextEvent.TYPE_ACTIVE_EDITOR) {
        if (consoleEditorHadFocusLast() || activeEditor_ == null)
            type = GetEditorContextEvent.TYPE_CONSOLE_EDITOR;
        else
            type = GetEditorContextEvent.TYPE_SOURCE_EDITOR;
    }
    if (type == GetEditorContextEvent.TYPE_CONSOLE_EDITOR) {
        InputEditorDisplay editor = consoleEditorProvider_.getConsoleEditor();
        if (editor != null && editor instanceof DocDisplay) {
            getEditorContext("#console", "", (DocDisplay) editor);
            return;
        }
    } else if (type == GetEditorContextEvent.TYPE_SOURCE_EDITOR) {
        EditingTarget target = activeEditor_;
        if (target != null && target instanceof TextEditingTarget) {
            getEditorContext(target.getId(), target.getPath(), ((TextEditingTarget) target).getDocDisplay());
            return;
        }
    }
    // We need to ensure a 'getEditorContext' event is always
    // returned as we have a 'wait-for' event on the server side
    server_.getEditorContextCompleted(GetEditorContextEvent.SelectionData.create(), new VoidServerRequestCallback());
}
Also used : InputEditorDisplay(org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorDisplay) GetEditorContextEvent(org.rstudio.studio.client.events.GetEditorContextEvent) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditingTarget(org.rstudio.studio.client.workbench.views.source.editors.EditingTarget) DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) CodeBrowserEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) DocDisplay(org.rstudio.studio.client.workbench.views.source.editors.text.DocDisplay)

Aggregations

DocDisplay (org.rstudio.studio.client.workbench.views.source.editors.text.DocDisplay)2 JsArrayString (com.google.gwt.core.client.JsArrayString)1 GetEditorContextEvent (org.rstudio.studio.client.events.GetEditorContextEvent)1 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)1 InputEditorDisplay (org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorDisplay)1 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)1 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)1 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)1 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)1 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)1