EWA

代码编辑采用微软的Monaco.Editor

2016-10-25

代码编辑采用微软的Monaco.Editor

原因是原来的ACE在chrome版本v53以上时输入中文出现bug。
var mode = monaco.editor.createModel("", "markdown");
var theme_code = "vs-dark";
if (window.localStorage && window.localStorage["EWA_CODE_THENE"]) {
    var v = window.localStorage["EWA_CODE_THENE"];
    var obj = document.getElementById('theme');
    for (var i = 0; i < theme.options.length; i++) {
        var v1 = obj.options[i].value;
        if (v1 == v) {
            theme_code = v1;
            obj.value = v1;
            break;
        }
    }
}

require([ 'vs/editor/editor.main' ], function() {
    editor = monaco.editor.create(document.getElementById('code'), {
        model : mode,
        'theme' : theme_code,
        lineHeight : 25,
        fontSize : 14,
        wordWrap : true
    });

    //保存
    editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, function(a) {
        try {
            parent.save();
        } catch (e) {
            console.log(e);
        }
    });
    window.onresize = function() {
        if (editor) {
            editor.layout();
        }
    };
    window.setInterval(update,500);
});