<commit_before>var editor = null;
$(function () {
    // enable CodeMirror
    editor = CodeMirror.fromTextArea($('#Editor').get(0), {
        mode: "gfm",
        lineWrapping: true
    });
    $('.CodeMirror').attr('id', 'CodeMirror').addClass('tab-pane active');

    // live preview
    var preview = function () {
        var value = editor.getValue();
        while (value.match(/(\[\[([^\]\[\|]+)(\|([^\]\[]*))?\]\])/)) {
            var bracketLink = RegExp.$1;
            var title = RegExp.$2;
            var alias = RegExp.$4;
            if (alias === '') {
                alias = title;
            }
            value = value.replace(bracketLink, '['+title+'](/page/'+encodeURIComponent(alias.replace(/\//g, '-'))+')');
        }
        $('#Preview').html(marked(value).replace(/<table>/g, '<table class="table table-bordered table-striped">'));
    };
    CodeMirror.on(editor, "change", preview);
    preview();

    // scroll sync
    $('.CodeMirror-scroll').on('scroll', function(e){
        var other = $('#Preview').get(0);
        var percentage = this.scrollTop / (this.scrollHeight - this.offsetHeight);
        other.scrollTop = percentage * (other.scrollHeight - other.offsetHeight);
    });

    // editor toolbox
    /*
    $('.btn-toolbar .btn[data-toggle!="dropdown"]').click(function () {
        $(this).blur();
        editor.focus();
    });
    $('.btn-bold').click(function () {
        var str = editor.doc.getSelection();
        editor.doc.replaceSelection('**'+str+'**');
    });
    $('.btn-italic').click(function () {
        var str = editor.doc.getSelection();
        editor.doc.replaceSelection('*'+str+'*');
    });
    var insertLineHead = function (stringHead, insertIndent) {
        var cursor = editor.doc.getCursor();
        var lineHandle = editor.doc.getLineHandle(cursor.line);
        if (lineHandle.text.replace(/(^\s+)|(\s+$)/g, "") === "") {
            editor.doc.setSelection(cursor);
            editor.doc.replaceSelection(stringHead);
        } else {
            editor.doc.setSelection({line: cursor.line, ch: 9999});
            var indent = '';
            if (insertIndent) {
                indent = lineHandle.text.replace(/^([\s]*).*$/, "$1");
            }
            editor.doc.replaceSelection("\n"+indent+stringHead);
        }
    };
    $('.btn-list-ul').click(function () {
        insertLineHead('* ', true);
    });
    $('.btn-list-ol').click(function () {
        insertLineHead('1. ', true);
    });
    $('.btn-header').click(function () {
        var headString = '';
        for (var i=1;i<=$(this).attr('data-header');i++) {
            headString += '#';
        }
        insertLineHead(headString+' ', false);
        $('.dropdown.open').removeClass('open');
        $('.btn-header').blur();
        editor.focus();
        return false;
    });
    $('.btn-chain').click(function () {
        var str = editor.doc.getSelection();
        editor.doc.replaceSelection('['+str+']()');
    });
    var replaceLineHead = function (stringHead) {
        var cursor = editor.doc.getCursor();
        var lineHandle = editor.doc.getLineHandle(cursor.line);
        if (lineHandle.text.replace(/(^\s+)|(\s+$)/g, "") === "") {
            editor.doc.setSelection(cursor);
            editor.doc.replaceSelection(stringHead);
        } else {
            editor.doc.setSelection({line: cursor.line, ch: 9999});
            var indent = '';
            if (insertIndent) {
                indent = lineHandle.text.replace(/^([\s]*).*$/, "$1");
            }
            editor.doc.replaceSelection("\n"+indent+stringHead);
        }
    };
    $('.btn-quote').click(function () {

    });
    $('.btn-code').click(function () {

    });
    */
    $('.btn-fullscreen').click(function () {
        var target = $('.editor').get(0);
        if (target.webkitRequestFullscreen) {
            // Chrome15+, Safari5.1+, Opera15+
            target.webkitRequestFullscreen();
        } else if (target.mozRequestFullScreen) {
            // Firefox 10+
            target.mozRequestFullScreen();
        } else if (target.msRequestFullscreen) {
            //IE11+
            target.msRequestFullscreen();
        } else if (target.requestFullscreen) {
            // HTML5 Fullscreen API
            target.requestFullscreen();
        }
        return false;
    });
});<commit_msg>When modify page, focus editor.<commit_after>var editor = null;
$(function () {
    // enable CodeMirror
    editor = CodeMirror.fromTextArea($('#Editor').get(0), {
        mode: "gfm",
        lineWrapping: true
    });
    $('.CodeMirror').attr('id', 'CodeMirror').addClass('tab-pane active');

    // live preview
    var preview = function () {
        var value = editor.getValue();
        while (value.match(/(\[\[([^\]\[\|]+)(\|([^\]\[]*))?\]\])/)) {
            var bracketLink = RegExp.$1;
            var title = RegExp.$2;
            var alias = RegExp.$4;
            if (alias === '') {
                alias = title;
            }
            value = value.replace(bracketLink, '['+title+'](/page/'+encodeURIComponent(alias.replace(/\//g, '-'))+')');
        }
        $('#Preview').html(marked(value).replace(/<table>/g, '<table class="table table-bordered table-striped">'));
    };
    CodeMirror.on(editor, "change", preview);
    preview();

    // scroll sync
    $('.CodeMirror-scroll').on('scroll', function(e){
        var other = $('#Preview').get(0);
        var percentage = this.scrollTop / (this.scrollHeight - this.offsetHeight);
        other.scrollTop = percentage * (other.scrollHeight - other.offsetHeight);
    });

    // editor toolbox
    /*
    $('.btn-toolbar .btn[data-toggle!="dropdown"]').click(function () {
        $(this).blur();
        editor.focus();
    });
    $('.btn-bold').click(function () {
        var str = editor.doc.getSelection();
        editor.doc.replaceSelection('**'+str+'**');
    });
    $('.btn-italic').click(function () {
        var str = editor.doc.getSelection();
        editor.doc.replaceSelection('*'+str+'*');
    });
    var insertLineHead = function (stringHead, insertIndent) {
        var cursor = editor.doc.getCursor();
        var lineHandle = editor.doc.getLineHandle(cursor.line);
        if (lineHandle.text.replace(/(^\s+)|(\s+$)/g, "") === "") {
            editor.doc.setSelection(cursor);
            editor.doc.replaceSelection(stringHead);
        } else {
            editor.doc.setSelection({line: cursor.line, ch: 9999});
            var indent = '';
            if (insertIndent) {
                indent = lineHandle.text.replace(/^([\s]*).*$/, "$1");
            }
            editor.doc.replaceSelection("\n"+indent+stringHead);
        }
    };
    $('.btn-list-ul').click(function () {
        insertLineHead('* ', true);
    });
    $('.btn-list-ol').click(function () {
        insertLineHead('1. ', true);
    });
    $('.btn-header').click(function () {
        var headString = '';
        for (var i=1;i<=$(this).attr('data-header');i++) {
            headString += '#';
        }
        insertLineHead(headString+' ', false);
        $('.dropdown.open').removeClass('open');
        $('.btn-header').blur();
        editor.focus();
        return false;
    });
    $('.btn-chain').click(function () {
        var str = editor.doc.getSelection();
        editor.doc.replaceSelection('['+str+']()');
    });
    var replaceLineHead = function (stringHead) {
        var cursor = editor.doc.getCursor();
        var lineHandle = editor.doc.getLineHandle(cursor.line);
        if (lineHandle.text.replace(/(^\s+)|(\s+$)/g, "") === "") {
            editor.doc.setSelection(cursor);
            editor.doc.replaceSelection(stringHead);
        } else {
            editor.doc.setSelection({line: cursor.line, ch: 9999});
            var indent = '';
            if (insertIndent) {
                indent = lineHandle.text.replace(/^([\s]*).*$/, "$1");
            }
            editor.doc.replaceSelection("\n"+indent+stringHead);
        }
    };
    $('.btn-quote').click(function () {

    });
    $('.btn-code').click(function () {

    });
    */
    $('.btn-fullscreen').click(function () {
        var target = $('.editor').get(0);
        if (target.webkitRequestFullscreen) {
            // Chrome15+, Safari5.1+, Opera15+
            target.webkitRequestFullscreen();
        } else if (target.mozRequestFullScreen) {
            // Firefox 10+
            target.mozRequestFullScreen();
        } else if (target.msRequestFullscreen) {
            //IE11+
            target.msRequestFullscreen();
        } else if (target.requestFullscreen) {
            // HTML5 Fullscreen API
            target.requestFullscreen();
        }
        return false;
    });

    editor.focus();
});
{'fraction_non_alphanumeric': 0.1988370767301334, 'fraction_numerical': 0.006612700946300308, 'mean_word_length': 2.0725043782837127, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '191125', 'n_tokens_mistral': 2605, 'n_tokens_neox': 2531, 'n_words': 393}