<commit_before>var MagTool = MagTool || {};

(function(window, $, app, Mousetrap) {
    var magazineBuilder = window.magazineBuilder;
    
    app.modules = {};
    
    app.$doc = $(window.document);
    app.$body = $('body');
    
    app.getLanguage = function() {
        return app.$body.data('language');
    };
    
    var resolveAction = app.resolveAction = function(actionName, params) {
        var action = app[actionName];
        
        if (typeof params === 'undefined') {
            params = [];
        }
        
        if (action) {
            if (
                action.always ||
                app.ContentEditor.isEditing() && action.whenEditing ||
                ! app.ContentEditor.isEditing() && ! action.whenEditing
            ) {
                return action.apply(app, params);
            }
        }
    };
    
    var registerAction = function(name, action, always, whenEditing) {
        action.always = always;
        
        if (! always) {
            action.whenEditing = whenEditing;
        }
        
        app[name] = action;
    };
    
    /**
     * Bind actions.
     */
    app.registerBindings = function() {
        // Click bindings
        app.UI.getUI().on('click', '[data-action]', function() {
            resolveAction($(this).data('action'));
        });
        
        // Change bindings
        app.UI.getUI().find('input[data-change], textarea[data-change], select[data-change]').on('change paste', function() {
            var value;
            var $this = $(this);
            var $group = $([]);
            
            if ($this.is('.uRadioBtn') || $this.is('.multi-input') || $this.is('[type="checkbox"]') || $this.is('[type="radio"]')) {
                var name = $this.attr('name');
                $group = app.UI.getUI().find('input[name="' + name + '"]');
            }
            
            if ($this.is('.uRadioBtn')) {
                $group.not($this).prop('checked', false);
                
                value = $group.filter(':checked').val();
            } else if ($this.is('.multi-input')) {
                value = [];
                
                $group.each(function() {
                    value.push($(this).val());
                });
            } else if ($this.is('[type="checkbox"]')) {
                value = [];
                
                $group.filter(':checked').each(function() {
                    value.push($(this).val());
                });
            } else if ($this.is('[type="radio"]')) {
                value = $group.filter(':checked').val();
            } else {
                value = $this.val();
            }
            
            if (! (value instanceof Array)) {
                value = [value];
            }
            
            resolveAction($this.data('change'), value);
        });
        
        // Notify close
        app.UI.getNotification().find('.fa-close').click(function() {
            app.UI.getNotification().removeClass('--open');
        });
    };
    
    /**
     * Bind key events to actions.
     */
    app.registerKeyBindings = function() {
        // First find existing key events on the body.
        var originalKeyEvents = $.grep(
            $._data(window.document, 'events').keyup || [],
            function(e) {
                return typeof e.selector === 'undefined';
            }
        );
        
        // Let's store them so we can unbind / rebind them later.
        app.$doc.data('originalKeyEvents', {
            bound: true,
            handlers: originalKeyEvents
        });
        
        // Reset Mousetrap in case any Mousetrap shortcuts are already bound.
        Mousetrap.reset();

        // Time to bind our own key events then.
        Mousetrap.bind('mod+e', function() {
            resolveAction('edit');
        });
        
        Mousetrap.bind('mod+s', function() {
            resolveAction('save');
        });
        
        Mousetrap.bind('mod+i', function() {
            resolveAction('map_image');
        });
        
        Mousetrap.bind('up', function(e) {
            e.preventDefault();
            
            app.ContentEditor.move('y', 1);
        });
        
        Mousetrap.bind('shift+up', function() {
            app.ContentEditor.move('y', 4);
        });
        
        Mousetrap.bind('right', function() {
            app.ContentEditor.move('x', 1);
        });
        
        Mousetrap.bind('shift+right', function() {
            app.ContentEditor.move('x', 4);
        });
        
        Mousetrap.bind('down', function(e) {
            e.preventDefault();
            
            app.ContentEditor.move('y', -1);
        });
        
        Mousetrap.bind('shift+down', function() {
            app.ContentEditor.move('y', -4);
        });
        
        Mousetrap.bind('left', function() {
            app.ContentEditor.move('x', -1);
        });
        
        Mousetrap.bind('shift+left', function() {
            app.ContentEditor.move('x', -4);
        });
        
        Mousetrap.bind(['backspace', 'del'], function(e) {
            e.preventDefault();
            
            app.ContentEditor.remove(app.ContentEditor.getSelection());
        });
        
        Mousetrap.bind('c', function() {
            app.ContentEditor.selectOnly(app.Credits.getCredits());
        });
        
        Mousetrap.bind('tab', function(e) {
            e.preventDefault();

            app.ContentEditor.selectNext();
        });
        
        Mousetrap.bind('shift+tab', function(e) {
            e.preventDefault();

            app.ContentEditor.selectPrev();
        });
        
        Mousetrap.bind('enter', function(e) {
            e.preventDefault();

            app.ContentEditor.startEditing(app.ContentEditor.getSelection().filter('.editable'));
        });<commit_msg>deselect elements before removing them<commit_after>var MagTool = MagTool || {};

(function(window, $, app, Mousetrap) {
    var magazineBuilder = window.magazineBuilder;
    
    app.modules = {};
    
    app.$doc = $(window.document);
    app.$body = $('body');
    
    app.getLanguage = function() {
        return app.$body.data('language');
    };
    
    var resolveAction = app.resolveAction = function(actionName, params) {
        var action = app[actionName];
        
        if (typeof params === 'undefined') {
            params = [];
        }
        
        if (action) {
            if (
                action.always ||
                app.ContentEditor.isEditing() && action.whenEditing ||
                ! app.ContentEditor.isEditing() && ! action.whenEditing
            ) {
                return action.apply(app, params);
            }
        }
    };
    
    var registerAction = function(name, action, always, whenEditing) {
        action.always = always;
        
        if (! always) {
            action.whenEditing = whenEditing;
        }
        
        app[name] = action;
    };
    
    /**
     * Bind actions.
     */
    app.registerBindings = function() {
        // Click bindings
        app.UI.getUI().on('click', '[data-action]', function() {
            resolveAction($(this).data('action'));
        });
        
        // Change bindings
        app.UI.getUI().find('input[data-change], textarea[data-change], select[data-change]').on('change paste', function() {
            var value;
            var $this = $(this);
            var $group = $([]);
            
            if ($this.is('.uRadioBtn') || $this.is('.multi-input') || $this.is('[type="checkbox"]') || $this.is('[type="radio"]')) {
                var name = $this.attr('name');
                $group = app.UI.getUI().find('input[name="' + name + '"]');
            }
            
            if ($this.is('.uRadioBtn')) {
                $group.not($this).prop('checked', false);
                
                value = $group.filter(':checked').val();
            } else if ($this.is('.multi-input')) {
                value = [];
                
                $group.each(function() {
                    value.push($(this).val());
                });
            } else if ($this.is('[type="checkbox"]')) {
                value = [];
                
                $group.filter(':checked').each(function() {
                    value.push($(this).val());
                });
            } else if ($this.is('[type="radio"]')) {
                value = $group.filter(':checked').val();
            } else {
                value = $this.val();
            }
            
            if (! (value instanceof Array)) {
                value = [value];
            }
            
            resolveAction($this.data('change'), value);
        });
        
        // Notify close
        app.UI.getNotification().find('.fa-close').click(function() {
            app.UI.getNotification().removeClass('--open');
        });
    };
    
    /**
     * Bind key events to actions.
     */
    app.registerKeyBindings = function() {
        // First find existing key events on the body.
        var originalKeyEvents = $.grep(
            $._data(window.document, 'events').keyup || [],
            function(e) {
                return typeof e.selector === 'undefined';
            }
        );
        
        // Let's store them so we can unbind / rebind them later.
        app.$doc.data('originalKeyEvents', {
            bound: true,
            handlers: originalKeyEvents
        });
        
        // Reset Mousetrap in case any Mousetrap shortcuts are already bound.
        Mousetrap.reset();

        // Time to bind our own key events then.
        Mousetrap.bind('mod+e', function() {
            resolveAction('edit');
        });
        
        Mousetrap.bind('mod+s', function() {
            resolveAction('save');
        });
        
        Mousetrap.bind('mod+i', function() {
            resolveAction('map_image');
        });
        
        Mousetrap.bind('up', function(e) {
            e.preventDefault();
            
            app.ContentEditor.move('y', 1);
        });
        
        Mousetrap.bind('shift+up', function() {
            app.ContentEditor.move('y', 4);
        });
        
        Mousetrap.bind('right', function() {
            app.ContentEditor.move('x', 1);
        });
        
        Mousetrap.bind('shift+right', function() {
            app.ContentEditor.move('x', 4);
        });
        
        Mousetrap.bind('down', function(e) {
            e.preventDefault();
            
            app.ContentEditor.move('y', -1);
        });
        
        Mousetrap.bind('shift+down', function() {
            app.ContentEditor.move('y', -4);
        });
        
        Mousetrap.bind('left', function() {
            app.ContentEditor.move('x', -1);
        });
        
        Mousetrap.bind('shift+left', function() {
            app.ContentEditor.move('x', -4);
        });
        
        Mousetrap.bind(['backspace', 'del'], function(e) {
            e.preventDefault();
            
            app.ContentEditor.deselectAll();
            app.ContentEditor.remove(app.ContentEditor.getSelection());
        });
        
        Mousetrap.bind('c', function() {
            app.ContentEditor.selectOnly(app.Credits.getCredits());
        });
        
        Mousetrap.bind('tab', function(e) {
            e.preventDefault();

            app.ContentEditor.selectNext();
        });
        
        Mousetrap.bind('shift+tab', function(e) {
            e.preventDefault();

            app.ContentEditor.selectPrev();
        });
        
        Mousetrap.bind('enter', function(e) {
            e.preventDefault();

            app.ContentEditor.startEditing(app.ContentEditor.getSelection().filter('.editable'));
        });
{'fraction_non_alphanumeric': 0.15805084745762712, 'fraction_numerical': 0.0013559322033898306, 'mean_word_length': 1.4271904566022213, 'pattern_counts': {'":': 0, '<': 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': '344524', 'n_tokens_mistral': 3247, 'n_tokens_neox': 3192, 'n_words': 507}