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

define(function (require, exports, module) {
    "use strict";

    var AppInit = brackets.getModule("utils/AppInit");
    var WorkspaceManager = brackets.getModule("view/WorkspaceManager");
    var MainViewManager = brackets.getModule("view/MainViewManager");
    var EditorManager = brackets.getModule("editor/EditorManager");
    var Editor = brackets.getModule("editor/Editor");
    var ExtensionUtils = brackets.getModule("utils/ExtensionUtils");
    var CommandManager = brackets.getModule("command/CommandManager");
    var Menus = brackets.getModule("command/Menus");
    var Dialogs = brackets.getModule("widgets/Dialogs");
    var PreferencesManager = brackets.getModule("preferences/PreferencesManager");
    var Strings = brackets.getModule("strings");
    
    var prefs = PreferencesManager.getExtensionPrefs("maupin.cursor");
    var $template = $(Mustache.render(require("text!html/cursor-settings.html"), {"Strings": Strings}));
    var commandId = "maupin.cursor.openSettings";
    var editors = [];
    var cssNode = null;
    var viewMenu;
    var viewMenuCommands;
    var currentEditor = EditorManager.getCurrentFullEditor();
    var addChar = false;
    
    // NOTE: access to ._codeMirror may disappear in future releases of Brackets
    // discussion here:
    // https://github.com/adobe/brackets/issues/8751
    // without access to the codeMirror object, this extension will break

    function refreshCursorOptions(editor) {
        
        var width = editor._codeMirror.defaultCharWidth();
        
        var cursorStyle = prefs.get("cursorStyle");
        var cursorColor = prefs.get("cursorColor");
        var textColor = prefs.get("textColor");
        var blinkRate = prefs.get("blinkRate");
        var css;
        
        addChar = cursorStyle === 'block';
        
        if (cursorStyle === 'block') {
            css = "#editor-holder .CodeMirror-cursor {border-left: none !important;width: " + width + "px !important;background-color: " + cursorColor + " !important;color: " + textColor + " !important;}";
        } else if (cursorStyle === 'horizontal') {
            css = "#editor-holder .CodeMirror-cursor {border-left: none !important;width: " + width + "px !important;border-bottom: 1px solid " + cursorColor + " !important;}";
        } else if (cursorStyle === 'vertical') {
            css = "#editor-holder .CodeMirror-cursor {width: " + width + "px !important;border-left: 1px solid " + cursorColor + " !important;}";
        }

        if (cssNode) {
            cssNode.parentNode.removeChild(cssNode);
        }
        cssNode = ExtensionUtils.addEmbeddedStyleSheet(css);
        
        if (blinkRate || blinkRate === 0) {
            editor._codeMirror.setOption('cursorBlinkRate', blinkRate);
        }
        
    }
    
    function showDialog() {
        var d = Dialogs.showModalDialogUsingTemplate($template, true);
        var dialog = d.getElement();
        var cursor = $('.CodeMirror-cursor');
        var currentColor = cursor.css('border-left-color');
        
        function ghostTextColorGroup() {
            if (dialog.find('#cursorStyle').val() === 'block') {
                dialog.find('#textColorGroup').css({opacity: '1'}).find('input').attr('disabled', false);
            } else {
                dialog.find('#textColorGroup').css({opacity: '.3'}).find('input').attr('disabled', true);
            }
        }
        
        dialog.find('#cursorStyle').val(prefs.get("cursorStyle") || 'vertical');
        dialog.find('#cursorColor').val(prefs.get("cursorColor") || currentColor);
        dialog.find('#textColor').val(prefs.get("textColor") || 'transparent');
        dialog.find('#blinkRate').val(prefs.get("blinkRate") || currentEditor._codeMirror.getOption('cursorBlinkRate'));
        dialog.find('#cursorStyle').change(ghostTextColorGroup);
        
        ghostTextColorGroup();
        
        d.done(function (buttonId) {
            var blinkRate;
            if (buttonId === 'done') {
                prefs.set("cursorStyle", dialog.find('#cursorStyle').val());
                prefs.set("cursorColor", dialog.find('#cursorColor').val());
                prefs.set("textColor", dialog.find('#textColor').val());
                blinkRate = parseInt(dialog.find('#blinkRate').val(), 10) || 0;
                if (blinkRate < 0) {
                    blinkRate = 0;
                }
                prefs.set("blinkRate", blinkRate);
                prefs.save();
                refreshCursorOptions(currentEditor);
            }
            EditorManager.getCurrentFullEditor()._codeMirror.refresh();
        });
    }

    function updateCursor(editor) {
        setTimeout(function () {
            // CodeMirror continually empties the cursor div on any activity
            // so we update on the next tick.
            var document = editor.document;
            var selections = editor.getSelections();
            var cursorElements = window.document.getElementsByClassName("CodeMirror-cursor");
            var chars = [];
            var cursors = [];
            var i;
            selections.forEach(function (selection) {<commit_msg>dialog no longer assume full editor exists, fixes #1<commit_after>/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, Mustache */

define(function (require, exports, module) {
    "use strict";

    var AppInit = brackets.getModule("utils/AppInit");
    var WorkspaceManager = brackets.getModule("view/WorkspaceManager");
    var MainViewManager = brackets.getModule("view/MainViewManager");
    var EditorManager = brackets.getModule("editor/EditorManager");
    var Editor = brackets.getModule("editor/Editor");
    var ExtensionUtils = brackets.getModule("utils/ExtensionUtils");
    var CommandManager = brackets.getModule("command/CommandManager");
    var Menus = brackets.getModule("command/Menus");
    var Dialogs = brackets.getModule("widgets/Dialogs");
    var PreferencesManager = brackets.getModule("preferences/PreferencesManager");
    var Strings = brackets.getModule("strings");
    
    var prefs = PreferencesManager.getExtensionPrefs("maupin.cursor");
    var $template = $(Mustache.render(require("text!html/cursor-settings.html"), {"Strings": Strings}));
    var commandId = "maupin.cursor.openSettings";
    var editors = [];
    var cssNode = null;
    var viewMenu;
    var viewMenuCommands;
    var currentEditor = EditorManager.getCurrentFullEditor();
    var addChar = false;
    
    // NOTE: access to ._codeMirror may disappear in future releases of Brackets
    // discussion here:
    // https://github.com/adobe/brackets/issues/8751
    // without access to the codeMirror object, this extension will break

    function refreshCursorOptions(editor) {
        
        var width = editor._codeMirror.defaultCharWidth();
        
        var cursorStyle = prefs.get("cursorStyle");
        var cursorColor = prefs.get("cursorColor");
        var textColor = prefs.get("textColor");
        var blinkRate = prefs.get("blinkRate");
        var css;
        
        addChar = cursorStyle === 'block';
        
        if (cursorStyle === 'block') {
            css = "#editor-holder .CodeMirror-cursor {border-left: none !important;width: " + width + "px !important;background-color: " + cursorColor + " !important;color: " + textColor + " !important;}";
        } else if (cursorStyle === 'horizontal') {
            css = "#editor-holder .CodeMirror-cursor {border-left: none !important;width: " + width + "px !important;border-bottom: 1px solid " + cursorColor + " !important;}";
        } else if (cursorStyle === 'vertical') {
            css = "#editor-holder .CodeMirror-cursor {width: " + width + "px !important;border-left: 1px solid " + cursorColor + " !important;}";
        }

        if (cssNode) {
            cssNode.parentNode.removeChild(cssNode);
        }
        cssNode = ExtensionUtils.addEmbeddedStyleSheet(css);
        
        if (blinkRate || blinkRate === 0) {
            editor._codeMirror.setOption('cursorBlinkRate', blinkRate);
        }
        
    }
    
    function showDialog() {
        var d = Dialogs.showModalDialogUsingTemplate($template, true);
        var dialog = d.getElement();
        var cursor = $('.CodeMirror-cursor');
        var currentColor = cursor.css('border-left-color');
        var currentBlinkRate;
        
        function ghostTextColorGroup() {
            if (dialog.find('#cursorStyle').val() === 'block') {
                dialog.find('#textColorGroup').css({opacity: '1'}).find('input').attr('disabled', false);
            } else {
                dialog.find('#textColorGroup').css({opacity: '.3'}).find('input').attr('disabled', true);
            }
        }
        
        if (currentEditor) {
            currentBlinkRate = currentEditor._codeMirror.getOption('cursorBlinkRate');
        } else {
            currentBlinkRate = 530;
        }
        
        dialog.find('#cursorStyle').val(prefs.get("cursorStyle") || 'vertical');
        dialog.find('#cursorColor').val(prefs.get("cursorColor") || currentColor);
        dialog.find('#textColor').val(prefs.get("textColor") || 'transparent');
        dialog.find('#blinkRate').val(prefs.get("blinkRate") || currentBlinkRate);
        dialog.find('#cursorStyle').change(ghostTextColorGroup);
        
        ghostTextColorGroup();
        
        d.done(function (buttonId) {
            var blinkRate;
            if (buttonId === 'done') {
                prefs.set("cursorStyle", dialog.find('#cursorStyle').val());
                prefs.set("cursorColor", dialog.find('#cursorColor').val());
                prefs.set("textColor", dialog.find('#textColor').val());
                blinkRate = parseInt(dialog.find('#blinkRate').val(), 10) || 0;
                if (blinkRate < 0) {
                    blinkRate = 0;
                }
                prefs.set("blinkRate", blinkRate);
                prefs.save();
                refreshCursorOptions(currentEditor);
            }
            currentEditor = EditorManager.getCurrentFullEditor();
            if (currentEditor) {
                currentEditor._codeMirror.refresh();
            }
        });
    }

    function updateCursor(editor) {
        setTimeout(function () {
            // CodeMirror continually empties the cursor div on any activity
            // so we update on the next tick.
            var document = editor.document;
            var selections = editor.getSelections();
            var cursorElements = window.document.getElementsByClassName("CodeMirror-cursor");
            var chars = [];
            var cursors = [];
            var i;
            selections.forEach(function (selection) {
{'fraction_non_alphanumeric': 0.13802868365762308, 'fraction_numerical': 0.0034712706677628574, 'mean_word_length': 2.5545454545454547, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '6447039', 'n_tokens_mistral': 3023, 'n_tokens_neox': 2887, 'n_words': 599}