<commit_before>/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, Mustache */

// Handles status bar interactions 
define(function (require, exports) {
    "use strict";
    
    var CommandManager = brackets.getModule("command/CommandManager"),
        CodeMirror     = brackets.getModule("thirdparty/CodeMirror2/lib/codemirror"),
        ExCommandHistory = require("./ExCommandHistory"),
        cm,
        callback,
        $dialog,
        $input,
        inHistory;
    
    /**     
     * Setup Vim status bar, hook events and setup ExCommand history.
     * @param {CodeMirror} _cm The current CodeMirror instance.
     */
    function init(_cm) {
        cm = _cm;
        _attachVimderbar(cm);
        $dialog = $("#vimderbar");
        $input = $dialog.children("#command");
        $input.on("keydown", function (e) {
            var keyName = CodeMirror.keyName(e);
            var commandVal = $input.val();
            if (keyName === "Up" || keyName === "Down") {
                if (!inHistory && commandVal !== "") {
                    // stash current command if exists so you can get back to it
                    ExCommandHistory.add(commandVal);
                }
                if (keyName === "Up") {
                    $input.val(ExCommandHistory.getPrevHistoryItem());
                } else {
                    $input.val(ExCommandHistory.getNextHistoryItem());
                }
                inHistory = true;
            } else if (e.keyCode === 13 || keyName === "Enter") {
                CodeMirror.e_stop(e);
                ExCommandHistory.add(commandVal);
                cm.focus();
                callback(commandVal);
            } else if (keyName === "Esc" || keyName === "Ctrl-C" || keyName === "Ctrl-[") {
                CodeMirror.e_stop(e);
                $input.blur();
                cm.focus();
            }
        });
        $input.on("blur", function () {
            $input.val("");
            $input.hide();
            $dialog.children("#command-sign").text("");
            $dialog.children("#command-info").text("");
            if (!$dialog.children("#confirm").is(":visible")) { // if #confirm hidden, show mode
                $dialog.children("#mode").show();
            }
            inHistory = false;
            ExCommandHistory.exitHistory();
            cm.focus();
        });
        ExCommandHistory.init();
    }
    /**     
     * Wipe out project command history.
     */
    function resetHistory() {
        // TODO: clean out localStorage
        ExCommandHistory.resetHistory();
    }
    /**     
     * Attach Vim functions to current CodeMirror instance,
     * add watch for mode changes on current instance.
     * @param {CodeMirror} _cm The current CodeMirror instance.
     */
    function _attachVimderbar(cm) {
        // this should use CodeMirror.defineExtension but
        // we're too late to change the prototype when Dialog is loaded
        cm.openDialog = CodeMirror.openDialog;
        cm.updateVimStatus = CodeMirror.updateVimStatus;
        cm.clearVimCommandKeys = CodeMirror.clearVimCommandKeys;
        cm.updateVimCommandKeys = CodeMirror.updateVimCommandKeys;
        
        cm.on("vim-mode-change", function (event) {
            var mode = event.mode;
            CodeMirror.updateVimStatus(mode);
        });
    }
    /**     
     * Change current editor instance to cm.
     * @param {CodeMirror} _cm The current CodeMirror instance.
     */
    function changeDocument(cm) {
        if (cm) {
            _attachVimderbar(cm);
        }
    }
    /**     
     * Open command dialog overlay in status bar.
     * @param {String} template Template HTML for dialog, generated by CodeMirror Dialog.
     */
    function openDialog(template, _callback) {
        callback = _callback;
        // grab shortText out of the provided template
        // TODO: this could be brittle, is the template format going to change?
        var shortText = $(Mustache.render(template))[0].innerHTML;
        if (shortText === null) { // dealing with Macros
            $dialog.children("#mode").html(template);
            return function (closing) {
                if (closing) {
                    return false;
                } else {
                    return true;
                }
            };
        } else if (shortText[0] === "/") {
            // "/" and "?" search used to be integrated with the Vim.js file and
            // the status bar, but I think the native Brackets search is much more
            // efficient. @ff.
            CommandManager.execute("edit.find");
            return;
        }
        var closed = false;
        function close() {
            if (closed) {
                return;
            }
            closed = true;
            // dialog.something;
        }
        $input.show();
        $input.focus();
        $dialog.children("#command-sign").text(shortText[0]);
        $dialog.children("#mode").hide();
        $dialog.children("#confirm").hide();
        return close;
    }
    /**
     * Change mode in status bar.
     * @param {String} mode Current Vim mode.
     */
    function updateVimStatus(mode) {
        if ($dialog) {
            $dialog.children("#mode").show();
            $dialog.children("#confirm").hide();
            $dialog.children("#mode").text("-- " + mode + " --");<commit_msg>edit.find is deprecated, switching to cmd.find<commit_after>/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, Mustache */

// Handles status bar interactions 
define(function (require, exports) {
    "use strict";
    
    var CommandManager = brackets.getModule("command/CommandManager"),
        CodeMirror     = brackets.getModule("thirdparty/CodeMirror2/lib/codemirror"),
        ExCommandHistory = require("./ExCommandHistory"),
        cm,
        callback,
        $dialog,
        $input,
        inHistory;
    
    /**     
     * Setup Vim status bar, hook events and setup ExCommand history.
     * @param {CodeMirror} _cm The current CodeMirror instance.
     */
    function init(_cm) {
        cm = _cm;
        _attachVimderbar(cm);
        $dialog = $("#vimderbar");
        $input = $dialog.children("#command");
        $input.on("keydown", function (e) {
            var keyName = CodeMirror.keyName(e);
            var commandVal = $input.val();
            if (keyName === "Up" || keyName === "Down") {
                if (!inHistory && commandVal !== "") {
                    // stash current command if exists so you can get back to it
                    ExCommandHistory.add(commandVal);
                }
                if (keyName === "Up") {
                    $input.val(ExCommandHistory.getPrevHistoryItem());
                } else {
                    $input.val(ExCommandHistory.getNextHistoryItem());
                }
                inHistory = true;
            } else if (e.keyCode === 13 || keyName === "Enter") {
                CodeMirror.e_stop(e);
                ExCommandHistory.add(commandVal);
                cm.focus();
                callback(commandVal);
            } else if (keyName === "Esc" || keyName === "Ctrl-C" || keyName === "Ctrl-[") {
                CodeMirror.e_stop(e);
                $input.blur();
                cm.focus();
            }
        });
        $input.on("blur", function () {
            $input.val("");
            $input.hide();
            $dialog.children("#command-sign").text("");
            $dialog.children("#command-info").text("");
            if (!$dialog.children("#confirm").is(":visible")) { // if #confirm hidden, show mode
                $dialog.children("#mode").show();
            }
            inHistory = false;
            ExCommandHistory.exitHistory();
            cm.focus();
        });
        ExCommandHistory.init();
    }
    /**     
     * Wipe out project command history.
     */
    function resetHistory() {
        // TODO: clean out localStorage
        ExCommandHistory.resetHistory();
    }
    /**     
     * Attach Vim functions to current CodeMirror instance,
     * add watch for mode changes on current instance.
     * @param {CodeMirror} _cm The current CodeMirror instance.
     */
    function _attachVimderbar(cm) {
        // this should use CodeMirror.defineExtension but
        // we're too late to change the prototype when Dialog is loaded
        cm.openDialog = CodeMirror.openDialog;
        cm.updateVimStatus = CodeMirror.updateVimStatus;
        cm.clearVimCommandKeys = CodeMirror.clearVimCommandKeys;
        cm.updateVimCommandKeys = CodeMirror.updateVimCommandKeys;
        
        cm.on("vim-mode-change", function (event) {
            var mode = event.mode;
            CodeMirror.updateVimStatus(mode);
        });
    }
    /**     
     * Change current editor instance to cm.
     * @param {CodeMirror} _cm The current CodeMirror instance.
     */
    function changeDocument(cm) {
        if (cm) {
            _attachVimderbar(cm);
        }
    }
    /**     
     * Open command dialog overlay in status bar.
     * @param {String} template Template HTML for dialog, generated by CodeMirror Dialog.
     */
    function openDialog(template, _callback) {
        callback = _callback;
        // grab shortText out of the provided template
        // TODO: this could be brittle, is the template format going to change?
        var shortText = $(Mustache.render(template))[0].innerHTML;
        if (shortText === null) { // dealing with Macros
            $dialog.children("#mode").html(template);
            return function (closing) {
                if (closing) {
                    return false;
                } else {
                    return true;
                }
            };
        } else if (shortText[0] === "/") {
            // "/" and "?" search used to be integrated with the Vim.js file and
            // the status bar, but I think the native Brackets search is much more
            // efficient. @ff.
            CommandManager.execute("cmd.find");
            return;
        }
        var closed = false;
        function close() {
            if (closed) {
                return;
            }
            closed = true;
            // dialog.something;
        }
        $input.show();
        $input.focus();
        $dialog.children("#command-sign").text(shortText[0]);
        $dialog.children("#mode").hide();
        $dialog.children("#confirm").hide();
        return close;
    }
    /**
     * Change mode in status bar.
     * @param {String} mode Current Vim mode.
     */
    function updateVimStatus(mode) {
        if ($dialog) {
            $dialog.children("#mode").show();
            $dialog.children("#confirm").hide();
            $dialog.children("#mode").text("-- " + mode + " --");
{'fraction_non_alphanumeric': 0.1282497253753204, 'fraction_numerical': 0.0016477480776272428, 'mean_word_length': 1.7109181141439207, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '5768882', 'n_tokens_mistral': 2950, 'n_tokens_neox': 2826, 'n_words': 719}