<commit_before>/*
 * A mixin for views that provides key binding functionality.
 *
 * Views using this mixin can provide a keyBindings map that maps a set of
 * key characters to a function.
 */
RB.KeyBindingsMixin = {
    /*
     * Enables key bindings for the view.
     *
     * Begins listening for any key bindings registered in the view's
     * keyBindings map, and calls the appropriate function.
     *
     * By default, this is called automatically when setting up the view,
     * by way of delegateEvents.
     */
    delegateKeyBindings: function() {
        $(document.body).on('keypress.keybindings' + this.cid,
                            _.bind(function(evt) {
            var keyChar,
                keys,
                func;

            if (evt.altKey || evt.ctrlKey || evt.metaKey ||
                evt.target.tagName === 'INPUT' ||
                evt.target.tagName === 'TEXTAREA') {
                /* These are all unsupported, and things we want to ignore. */
                return;
            }

            keyChar = String.fromCharCode(evt.which);

            for (keys in this.keyBindings) {
                if (_.has(this.keyBindings, keys)
                    && keys.indexOf(keyChar) !== -1) {

                    evt.stopPropagation();
                    evt.preventDefault();

                    func = this.keyBindings[keys];

                    if (!_.isFunction(func)) {
                        func = this[func];
                    }

                    func.call(this, evt);
                    return;
                }
            }
        }, this));
    },

    /*
     * Disables key bindings for the view.
     *
     * By default, this is called automatically when calling undelegateEvents.
     */
    undelegateKeyBindings: function() {
        $(document.body).off('keypress.keybindings' + this.cid);
    },

    /*
     * Delegates both DOM events and key binding events.
     *
     * This overrides the default Backbone.View.delegateEvents to automatically
     * call delegateKeyBindings.
     */
    delegateEvents: function(events) {
        this.delegateKeyBindings();

        return Backbone.View.prototype.delegateEvents.call(this, events);
    },

    /*
     * Undelegates both DOM events and key binding events.
     *
     * This overrides the default Backbone.View.undelegateEvents to
     * automatically call undelegateKeyBindings.
     */
    undelegateEvents: function() {
        this.undelegateKeyBindings();

        return Backbone.View.prototype.undelegateEvents.call(this);
    }
};<commit_msg>Revert my prior keybinding fixes and fix the root cause of problems.<commit_after>/*
 * A mixin for views that provides key binding functionality.
 *
 * Views using this mixin can provide a keyBindings map that maps a set of
 * key characters to a function.
 */
RB.KeyBindingsMixin = {
    /*
     * Enables key bindings for the view.
     *
     * Begins listening for any key bindings registered in the view's
     * keyBindings map, and calls the appropriate function.
     *
     * By default, this is called automatically when setting up the view,
     * by way of delegateEvents.
     */
    delegateKeyBindings: function() {
        this.$el.on('keypress.keybindings' + this.cid, _.bind(function(evt) {
            var keyChar,
                keys,
                func;

            if (evt.altKey || evt.ctrlKey || evt.metaKey ||
                evt.target.tagName === 'INPUT' ||
                evt.target.tagName === 'TEXTAREA') {
                /* These are all unsupported, and things we want to ignore. */
                return;
            }

            keyChar = String.fromCharCode(evt.which);

            for (keys in this.keyBindings) {
                if (_.has(this.keyBindings, keys)
                    && keys.indexOf(keyChar) !== -1) {

                    evt.stopPropagation();
                    evt.preventDefault();

                    func = this.keyBindings[keys];

                    if (!_.isFunction(func)) {
                        func = this[func];
                    }

                    func.call(this, evt);
                    return;
                }
            }
        }, this));
    },

    /*
     * Disables key bindings for the view.
     *
     * By default, this is called automatically when calling undelegateEvents.
     */
    undelegateKeyBindings: function() {
        this.$el.off('keypress.keybindings' + this.cid);
    },

    /*
     * Delegates both DOM events and key binding events.
     *
     * This overrides the default Backbone.View.delegateEvents to automatically
     * call delegateKeyBindings.
     */
    delegateEvents: function(events) {
        var result = Backbone.View.prototype.delegateEvents.call(this, events);

        this.delegateKeyBindings();

        return result;
    },

    /*
     * Undelegates both DOM events and key binding events.
     *
     * This overrides the default Backbone.View.undelegateEvents to
     * automatically call undelegateKeyBindings.
     */
    undelegateEvents: function() {
        var result = Backbone.View.prototype.undelegateEvents.call(this);

        this.undelegateKeyBindings();

        return result;
    }
};
{'fraction_non_alphanumeric': 0.09566545732289479, 'fraction_numerical': 0.0003818980332251289, 'mean_word_length': 1.7153965785381027, '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': '1555944', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1361, 'n_words': 383}