<commit_before>module('lively.ide.CodeEditor').requires('lively.morphic', 'lively.ast.acorn').requiresLib({url: Config.codeBase + (false && lively.useMinifiedLibs ? 'lib/ace/lively-ace.min.js' : 'lib/ace/lively-ace.js'), loadTest: function() { return typeof ace !== 'undefined';}}).toRun(function() {

(function configureAce() {
    ace.config.set("workerPath", URL.codeBase.withFilename('lib/ace/').fullPath());
    // disable currently broken worker
    ace.require('ace/edit_session').EditSession.prototype.setUseWorker(false);
})();

lively.ide.ace = Object.extend(ace, {

    modules: function(optPrefix, shorten) {
        // return ace modules, optionally filtered by optPrefix. If shorten is
        // true remove optPrefix from name
        var moduleNames = Object.keys(ace.define.modules);
        if (!optPrefix) return moduleNames;
        moduleNames = moduleNames.select(function(ea) {
            return ea.startsWith(optPrefix); });
        if (!shorten) return moduleNames;
        return moduleNames.map(function(ea) {
            return ea.substring(optPrefix.length); })
    },

    // currently supported:
    // "abap", "clojure", "coffee", "css", "dart", "diff", "haml", "html",
    // "jade", "java", "javascript", "json", "latex", "less", "lisp",
    // "makefile", "markdown", "objectivec", "python", "r", "rdoc", "sh",
    // "sql", "svg", "text", "xml"
    // available but not loaded by default are:
    // "asciidoc", "c9search", "c_cpp", "coldfusion", "csharp", "curly",
    // "dot", "glsl", "golang", "groovy", "haxe", "jsp", "jsx", "liquid",
    // "lua", "luapage", "lucene", "ocaml", "perl", "pgsql", "php",
    // "powershell", "rhtml", "ruby", "scad", "scala", "scss", "stylus",
    // "tcl", "tex", "textile", "typescript", "vbscript", "xquery", "yaml"

    availableTextModes: function() {
        return lively.ide.ace.modules('ace/mode/', false)
            .select(function(moduleName) { return !!ace.require(moduleName).Mode })
            .map(function(name) { return name.substring('ace/mode/'.length); });
    },

    moduleNameForTextMode: function(textModeName) {
        return this.availableTextModes().include(textModeName) ?
            'ace/mode/' + textModeName : null;
    },

    // supported:
    // "ambiance", "monokai", "chrome", "pastel_on_dark", "textmate",
    // "solarized_dark", "twilight", "tomorrow", "tomorrow_night",
    // "tomorrow_night_blue", "tomorrow_night_bright", "eclipse"
    // not loaded by default are:
    // "xcode", "vibrant_ink", "tomorrow_night_eighties",
    // "tomorrow_night_bright", "tomorrow_night_blue", "solarized_light",
    // "mono_industrial", "merbivore_soft", "merbivore", "kr", "idle_fingers",
    // "github", "dreamweaver", "dawn", "crimson_editor", "cobalt",
    // "clouds_midnight", "clouds", "chaos"
    availableThemes: function() { return this.modules('ace/theme/', true) },

    moduleNameForTheme: function(themeName) {
        return this.availableThemes().include(themeName) ?
            "ace/theme/" + themeName : null
    }
});

lively.morphic.Shapes.External.subclass("lively.morphic.CodeEditorShape",
'settings', {
    // for now we do have a couple of optimizations in place that need the
    // shape to reference the aceEditor
    doNotSerialize: ["aceEditor"]
},
'intializing', {
    initialize: function($super) {
        var node = document.createElement('div');
        $super(node);
    }
},
'serialization', {

    onstore: function() {
        this.extent = this.getExtent();
    },

    onrestore: function() {
        this.shapeNode = document.createElement('div');
        lively.bindings.connect(this, 'aceEditor', this, 'setExtent', {
            removeAfterUpdate: true,
            converter: function(ed) { return this.targetObj.extent; }
        });
        lively.bindings.connect(this, 'aceEditor', this, 'setBorderWidth', {
            removeAfterUpdate: true,
            converter: function(ed) { return this.targetObj.getBorderWidth(); }
        });
    }
},
'HTML rendering', {

    getExtent: function($super) {
        return this.renderContextDispatch('getExtent') || this.extent || pt(0,0);
    },

    getExtentHTML: function ($super, ctx) {
        if (!this.aceEditor || !this._renderContext) return this.extent || $super(ctx);
        var borderW = this.getBorderWidth(),
            aceSize = this.aceEditor.renderer.$size;
        return lively.pt(aceSize.width + borderW, aceSize.height + borderW);
    },

    setExtentHTML: function (ctx, value) {
        if (!ctx.shapeNode) return undefined;
        var borderWidth = Math.floor(this.getBorderWidth()),
            realExtent = value.subXY(borderWidth, borderWidth).maxPt(lively.pt(0,0));
        ctx.domInterface.setExtent(ctx.shapeNode, realExtent);
        if (this.aceEditor) this.aceEditor.resize(true);
        return realExtent;
    }
});


lively.morphic.Morph.subclass('lively.morphic.CodeEditor',
'settings', {
    style: {
        enableGrabbing: false,
        fontSize: Config.get('defaultCodeFontSize'),
        gutter: Config.get('aceDefaultShowGutter'),
        textMode: Config.get('aceDefaultTextMode'),
        theme: Config.get('aceDefaultTheme'),
        lineWrapping: Config.get('aceDefaultLineWrapping'),
        invisibles: Config.get('aceDefaultShowInvisibles'),
        printMargin: Config.get('aceDefaultShowPrintMargin'),
        showActiveLine: Config.get('aceDefaultShowActiveLine'),
        showIndents: Config.get('aceDefaultShowIndents'),
        softTabs: Config.get('useSoftTabs'),
        autocompletion: Config.get('aceDefaultEnableAutocompletion')
    },
    doNotSerialize: ['_aceInitialized', 'aceEditor', 'aceEditorAfterSetupCallbacks', 'savedTextString'],<commit_msg>codeeditor: disable accept drops by default<commit_after>module('lively.ide.CodeEditor').requires('lively.morphic', 'lively.ast.acorn').requiresLib({url: Config.codeBase + (false && lively.useMinifiedLibs ? 'lib/ace/lively-ace.min.js' : 'lib/ace/lively-ace.js'), loadTest: function() { return typeof ace !== 'undefined';}}).toRun(function() {

(function configureAce() {
    ace.config.set("workerPath", URL.codeBase.withFilename('lib/ace/').fullPath());
    // disable currently broken worker
    ace.require('ace/edit_session').EditSession.prototype.setUseWorker(false);
})();

lively.ide.ace = Object.extend(ace, {

    modules: function(optPrefix, shorten) {
        // return ace modules, optionally filtered by optPrefix. If shorten is
        // true remove optPrefix from name
        var moduleNames = Object.keys(ace.define.modules);
        if (!optPrefix) return moduleNames;
        moduleNames = moduleNames.select(function(ea) {
            return ea.startsWith(optPrefix); });
        if (!shorten) return moduleNames;
        return moduleNames.map(function(ea) {
            return ea.substring(optPrefix.length); })
    },

    // currently supported:
    // "abap", "clojure", "coffee", "css", "dart", "diff", "haml", "html",
    // "jade", "java", "javascript", "json", "latex", "less", "lisp",
    // "makefile", "markdown", "objectivec", "python", "r", "rdoc", "sh",
    // "sql", "svg", "text", "xml"
    // available but not loaded by default are:
    // "asciidoc", "c9search", "c_cpp", "coldfusion", "csharp", "curly",
    // "dot", "glsl", "golang", "groovy", "haxe", "jsp", "jsx", "liquid",
    // "lua", "luapage", "lucene", "ocaml", "perl", "pgsql", "php",
    // "powershell", "rhtml", "ruby", "scad", "scala", "scss", "stylus",
    // "tcl", "tex", "textile", "typescript", "vbscript", "xquery", "yaml"

    availableTextModes: function() {
        return lively.ide.ace.modules('ace/mode/', false)
            .select(function(moduleName) { return !!ace.require(moduleName).Mode })
            .map(function(name) { return name.substring('ace/mode/'.length); });
    },

    moduleNameForTextMode: function(textModeName) {
        return this.availableTextModes().include(textModeName) ?
            'ace/mode/' + textModeName : null;
    },

    // supported:
    // "ambiance", "monokai", "chrome", "pastel_on_dark", "textmate",
    // "solarized_dark", "twilight", "tomorrow", "tomorrow_night",
    // "tomorrow_night_blue", "tomorrow_night_bright", "eclipse"
    // not loaded by default are:
    // "xcode", "vibrant_ink", "tomorrow_night_eighties",
    // "tomorrow_night_bright", "tomorrow_night_blue", "solarized_light",
    // "mono_industrial", "merbivore_soft", "merbivore", "kr", "idle_fingers",
    // "github", "dreamweaver", "dawn", "crimson_editor", "cobalt",
    // "clouds_midnight", "clouds", "chaos"
    availableThemes: function() { return this.modules('ace/theme/', true) },

    moduleNameForTheme: function(themeName) {
        return this.availableThemes().include(themeName) ?
            "ace/theme/" + themeName : null
    }
});

lively.morphic.Shapes.External.subclass("lively.morphic.CodeEditorShape",
'settings', {
    // for now we do have a couple of optimizations in place that need the
    // shape to reference the aceEditor
    doNotSerialize: ["aceEditor"]
},
'intializing', {
    initialize: function($super) {
        var node = document.createElement('div');
        $super(node);
    }
},
'serialization', {

    onstore: function() {
        this.extent = this.getExtent();
    },

    onrestore: function() {
        this.shapeNode = document.createElement('div');
        lively.bindings.connect(this, 'aceEditor', this, 'setExtent', {
            removeAfterUpdate: true,
            converter: function(ed) { return this.targetObj.extent; }
        });
        lively.bindings.connect(this, 'aceEditor', this, 'setBorderWidth', {
            removeAfterUpdate: true,
            converter: function(ed) { return this.targetObj.getBorderWidth(); }
        });
    }
},
'HTML rendering', {

    getExtent: function($super) {
        return this.renderContextDispatch('getExtent') || this.extent || pt(0,0);
    },

    getExtentHTML: function ($super, ctx) {
        if (!this.aceEditor || !this._renderContext) return this.extent || $super(ctx);
        var borderW = this.getBorderWidth(),
            aceSize = this.aceEditor.renderer.$size;
        return lively.pt(aceSize.width + borderW, aceSize.height + borderW);
    },

    setExtentHTML: function (ctx, value) {
        if (!ctx.shapeNode) return undefined;
        var borderWidth = Math.floor(this.getBorderWidth()),
            realExtent = value.subXY(borderWidth, borderWidth).maxPt(lively.pt(0,0));
        ctx.domInterface.setExtent(ctx.shapeNode, realExtent);
        if (this.aceEditor) this.aceEditor.resize(true);
        return realExtent;
    }
});


lively.morphic.Morph.subclass('lively.morphic.CodeEditor',
'settings', {
    style: {
        enableGrabbing: false, enableDropping: false,
        fontSize: Config.get('defaultCodeFontSize'),
        gutter: Config.get('aceDefaultShowGutter'),
        textMode: Config.get('aceDefaultTextMode'),
        theme: Config.get('aceDefaultTheme'),
        lineWrapping: Config.get('aceDefaultLineWrapping'),
        invisibles: Config.get('aceDefaultShowInvisibles'),
        printMargin: Config.get('aceDefaultShowPrintMargin'),
        showActiveLine: Config.get('aceDefaultShowActiveLine'),
        showIndents: Config.get('aceDefaultShowIndents'),
        softTabs: Config.get('useSoftTabs'),
        autocompletion: Config.get('aceDefaultEnableAutocompletion')
    },
    doNotSerialize: ['_aceInitialized', 'aceEditor', 'aceEditorAfterSetupCallbacks', 'savedTextString'],
{'fraction_non_alphanumeric': 0.16479693886424907, 'fraction_numerical': 0.0008696408383337682, 'mean_word_length': 3.4128933231005374, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2241698', 'n_tokens_mistral': 3651, 'n_tokens_neox': 3578, 'n_words': 682}