Search in sources :

Example 1 with ModeInfo

use of net.codemirror.mode.ModeInfo in project gerrit by GerritCodeReview.

the class EditScreen method setSyntaxHighlighting.

void setSyntaxHighlighting(boolean b) {
    ModeInfo modeInfo = ModeInfo.findMode(content.getContentType(), path);
    final String mode = modeInfo != null ? modeInfo.mime() : null;
    if (b && mode != null && !mode.isEmpty()) {
        injectMode(mode, new AsyncCallback<Void>() {

            @Override
            public void onSuccess(Void result) {
                cmBase.setOption("mode", mode);
                cmEdit.setOption("mode", mode);
            }

            @Override
            public void onFailure(Throwable caught) {
                prefs.syntaxHighlighting(false);
            }
        });
    } else {
        cmBase.setOption("mode", (String) null);
        cmEdit.setOption("mode", (String) null);
    }
}
Also used : ModeInfo(net.codemirror.mode.ModeInfo) NativeString(com.google.gerrit.client.rpc.NativeString)

Example 2 with ModeInfo

use of net.codemirror.mode.ModeInfo in project gerrit by GerritCodeReview.

the class EditScreen method initEditor.

private void initEditor() {
    ModeInfo mode = null;
    String editContent = "";
    if (content != null && content.getResult() != null) {
        editContent = content.getResult().asString();
        if (prefs.syntaxHighlighting()) {
            mode = ModeInfo.findMode(content.getContentType(), path);
        }
    }
    mv = MergeView.create(editor, Configuration.create().set("autoCloseBrackets", prefs.autoCloseBrackets()).set("cursorBlinkRate", prefs.cursorBlinkRate()).set("cursorHeight", 0.85).set("indentUnit", prefs.indentUnit()).set("keyMap", prefs.keyMapType().name().toLowerCase()).set("lineNumbers", prefs.hideLineNumbers()).set("lineWrapping", false).set("matchBrackets", prefs.matchBrackets()).set("mode", mode != null ? mode.mime() : null).set("origLeft", editContent).set("scrollbarStyle", "overlay").set("showTrailingSpace", prefs.showWhitespaceErrors()).set("styleSelectedText", true).set("tabSize", prefs.tabSize()).set("theme", prefs.theme().name().toLowerCase()).set("value", ""));
    cmBase = mv.leftOriginal();
    cmBase.getWrapperElement().addClassName(style.base());
    cmEdit = mv.editor();
    setCmBaseValue();
    cmEdit.setValue(editContent);
    CodeMirror.addCommand("save", new CommandRunner() {

        @Override
        public void run(CodeMirror instance) {
            save().run();
        }
    });
}
Also used : ModeInfo(net.codemirror.mode.ModeInfo) NativeString(com.google.gerrit.client.rpc.NativeString) CommandRunner(net.codemirror.lib.CodeMirror.CommandRunner) CodeMirror(net.codemirror.lib.CodeMirror)

Aggregations

NativeString (com.google.gerrit.client.rpc.NativeString)2 ModeInfo (net.codemirror.mode.ModeInfo)2 CodeMirror (net.codemirror.lib.CodeMirror)1 CommandRunner (net.codemirror.lib.CodeMirror.CommandRunner)1