<commit_before>/*
 * Copyright 2018 The CodeWorld Authors. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://w...content-available-to-author-only...e.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Initializes the programming environment.  This is called after the
 * entire document body and other JavaScript has loaded.
 */
function init() {
    allProjectNames = [[]];
    allFolderNames = [[]];
    openProjectName = null;
    nestedDirs = [""];

    if (window.location.pathname == '/haskell') {
        window.buildMode = 'haskell'
    } else {
        window.buildMode = 'codeworld';
    }

    var hash = location.hash.slice(1);
    if (hash.length > 0) {
        if (hash.slice(-2) == '==') {
            hash = hash.slice(0, -2);
        }
        if(hash[0] == 'F') {
            function go(folderName) {
                var id_token = auth2.currentUser.get().getAuthResponse().id_token;
                var data = new FormData();
                data.append('id_token', id_token);
                data.append('mode', window.buildMode);
                data.append('shash', hash);
                data.append('name', folderName);

                sendHttp('POST', 'shareContent', data, function(request) {
                    window.location.hash = '';
                    if (request.status == 200) {
                        sweetAlert('Success!', 'The shared folder is moved into your root directory.', 'success');
                    } else {
                        sweetAlert('Oops!', 'Could not load the shared directory. Please try again.', 'error');
                    }
                    initCodeworld();
                    registerStandardHints(function(){setMode(true);});
                    discoverProjects("", 0);
                    updateUI();
                });
            }

            sweetAlert({
                html: true,
                title: '<i class="mdi mdi-72px mdi-cloud-upload"></i>&nbsp; Save As',
                text: 'Enter a name for the shared folder:',
                type: 'input',
                confirmButtonText: 'Save',
                showCancelButton: false,
                closeOnConfirm: false
            }, go);
        } else {
            initCodeworld();
            registerStandardHints(function(){setMode(true);});
            updateUI();
        }
    } else {
        initCodeworld();
        registerStandardHints(function(){setMode(true);});
        updateUI();
    }
 
    if (hash.length > 0) {
        if (hash.slice(-2) == '==') {
            hash = hash.slice(0, -2);
        }
        if (hash[0] == 'P') {
            sendHttp('GET', 'loadSource?hash=' + hash + '&mode=' + window.buildMode, null, function(request) {
                if (request.status == 200) {
                    setCode(request.responseText, null, null, true);
                }
            });
        } else if (hash[0] != 'F') {
            setCode('');
        }
    } else {
        setCode('');
    }
}

function initCodeworld() {
    var editor = document.getElementById('editor');

    codeworldKeywords = {};

    window.codeworldEditor = CodeMirror.fromTextArea(editor, {
        mode: {
            name: 'codeworld',
            overrideKeywords: codeworldKeywords
        },
        lineNumbers: true,
        autofocus: true,
        matchBrackets: window.buildMode !== 'codeworld',
        highlightParams: window.buildMode === 'codeworld',
        styleActiveLine: !WURFL || !WURFL.is_mobile,
        showTrailingSpace: true,
        indentWithTabs: false,
        autoClearEmptyLines: true,
        highlightSelectionMatches: {
            showToken: /\w/,
            annotateScrollbar: true
        },
        rulers: [{
            column: 80,
            color: "#bbb",
            lineStyle: "dashed"
        }],
        extraKeys: {
            "Ctrl-Space": "autocomplete",
            "Shift-Space": "autocomplete",
            "Tab": "indentMore",
            "Shift-Tab": "indentLess",<commit_msg>Limit undo depth to 50.  This should save a bit on the size of saved projects.<commit_after>/*
 * Copyright 2018 The CodeWorld Authors. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://w...content-available-to-author-only...e.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Initializes the programming environment.  This is called after the
 * entire document body and other JavaScript has loaded.
 */
function init() {
    allProjectNames = [[]];
    allFolderNames = [[]];
    openProjectName = null;
    nestedDirs = [""];

    if (window.location.pathname == '/haskell') {
        window.buildMode = 'haskell'
    } else {
        window.buildMode = 'codeworld';
    }

    var hash = location.hash.slice(1);
    if (hash.length > 0) {
        if (hash.slice(-2) == '==') {
            hash = hash.slice(0, -2);
        }
        if(hash[0] == 'F') {
            function go(folderName) {
                var id_token = auth2.currentUser.get().getAuthResponse().id_token;
                var data = new FormData();
                data.append('id_token', id_token);
                data.append('mode', window.buildMode);
                data.append('shash', hash);
                data.append('name', folderName);

                sendHttp('POST', 'shareContent', data, function(request) {
                    window.location.hash = '';
                    if (request.status == 200) {
                        sweetAlert('Success!', 'The shared folder is moved into your root directory.', 'success');
                    } else {
                        sweetAlert('Oops!', 'Could not load the shared directory. Please try again.', 'error');
                    }
                    initCodeworld();
                    registerStandardHints(function(){setMode(true);});
                    discoverProjects("", 0);
                    updateUI();
                });
            }

            sweetAlert({
                html: true,
                title: '<i class="mdi mdi-72px mdi-cloud-upload"></i>&nbsp; Save As',
                text: 'Enter a name for the shared folder:',
                type: 'input',
                confirmButtonText: 'Save',
                showCancelButton: false,
                closeOnConfirm: false
            }, go);
        } else {
            initCodeworld();
            registerStandardHints(function(){setMode(true);});
            updateUI();
        }
    } else {
        initCodeworld();
        registerStandardHints(function(){setMode(true);});
        updateUI();
    }
 
    if (hash.length > 0) {
        if (hash.slice(-2) == '==') {
            hash = hash.slice(0, -2);
        }
        if (hash[0] == 'P') {
            sendHttp('GET', 'loadSource?hash=' + hash + '&mode=' + window.buildMode, null, function(request) {
                if (request.status == 200) {
                    setCode(request.responseText, null, null, true);
                }
            });
        } else if (hash[0] != 'F') {
            setCode('');
        }
    } else {
        setCode('');
    }
}

function initCodeworld() {
    var editor = document.getElementById('editor');

    codeworldKeywords = {};

    window.codeworldEditor = CodeMirror.fromTextArea(editor, {
        mode: {
            name: 'codeworld',
            overrideKeywords: codeworldKeywords
        },
        undoDepth: 50,
        lineNumbers: true,
        autofocus: true,
        matchBrackets: window.buildMode !== 'codeworld',
        highlightParams: window.buildMode === 'codeworld',
        styleActiveLine: !WURFL || !WURFL.is_mobile,
        showTrailingSpace: true,
        indentWithTabs: false,
        autoClearEmptyLines: true,
        highlightSelectionMatches: {
            showToken: /\w/,
            annotateScrollbar: true
        },
        rulers: [{
            column: 80,
            color: "#bbb",
            lineStyle: "dashed"
        }],
        extraKeys: {
            "Ctrl-Space": "autocomplete",
            "Shift-Space": "autocomplete",
            "Tab": "indentMore",
            "Shift-Tab": "indentLess",
{'fraction_non_alphanumeric': 0.1264138389886893, 'fraction_numerical': 0.00754047460634287, 'mean_word_length': 1.7725176759913925, 'pattern_counts': {'":': 8, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2055215', 'n_tokens_mistral': 2477, 'n_tokens_neox': 2348, 'n_words': 626}