Example usage for com.google.gwt.core.client JsArrayString join

List of usage examples for com.google.gwt.core.client JsArrayString join

Introduction

In this page you can find the example usage for com.google.gwt.core.client JsArrayString join.

Prototype

public final native String join(String separator) ;

Source Link

Document

Convert each element of the array to a String and join them with a comma separator.

Usage

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.rmd.SetupChunkOptionsPopupPanel.java

License:Open Source License

private String getChunkText() {
    int chunkStart = position_.getRow();
    int chunkEnd = findEndOfChunk();
    JsArrayString chunkText = widget_.getEditor().getSession().getLines(chunkStart + 1, chunkEnd - 1);
    return chunkText.join("\n");
}

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget.java

License:Open Source License

@Handler
void onExtractFunction() {
    if (!isCursorInRMode()) {
        showRModeWarning("Extract Function");
        return;/*from   w ww.jav  a2  s  . c  om*/
    }

    docDisplay_.focus();

    String initialSelection = docDisplay_.getSelectionValue();
    final String refactoringName = "Extract Function";
    final String pleaseSelectCodeMessage = "Please select the code to " + "extract into a function.";
    if (checkSelectionAndAlert(refactoringName, pleaseSelectCodeMessage, initialSelection))
        return;

    docDisplay_.fitSelectionToLines(false);

    final String code = docDisplay_.getSelectionValue();
    if (checkSelectionAndAlert(refactoringName, pleaseSelectCodeMessage, code))
        return;

    final String indentation = extractIndentation(code);
    server_.detectFreeVars(code, new RefactorServerRequestCallback(refactoringName) {
        @Override
        void doExtract(final JsArrayString response) {
            globalDisplay_.promptForText(refactoringName, "Function Name", "",
                    new OperationWithInput<String>() {
                        public void execute(String input) {
                            String prefix;
                            if (docDisplay_.getSelectionOffset(true) == 0)
                                prefix = "";
                            else
                                prefix = "\n";
                            String args = response != null ? response.join(", ") : "";
                            docDisplay_.replaceSelection(
                                    prefix + indentation + input.trim() + " <- " + "function (" + args + ") {\n"
                                            + StringUtil.indent(code, "  ") + "\n" + indentation + "}");
                        }
                    });
        }
    });
}