<commit_before>﻿; (function ($, window, document) {
    var pluginName = 'autoTabComplete',
        defaults = {
            prefixMatch: '[@]',
            values: [],
            get: function() {
                return this.values;
            }
        };

    function AutoTabComplete(element, options) {
        var element = element,
            options = $.extend({}, defaults, options),
            _defaults = defaults,
            _name = pluginName,
            _inAutoComplete,
            _text,
            _initial,
            _index,
            _caret,
            _prefix,
            _matchRegExp = new RegExp(options.prefixMatch + "\\S*$", "i"),
            Keys = { Tab: 9, Shift: 16 };

        reset();

        $(element).keydown(function (event) {
            if (event.which === Keys.Tab) {
                event.preventDefault();

                var offset = event.shiftKey ? -1 : 1;

                if (!_inAutoComplete) {
                    _text = $(this).val();
                    var sel = getSelection(this);
                    _caret = sel.end;

                    // find initial text (starts with prefix char)
                    var match = _text.substr(0, _caret).match(_matchRegExp);
                    if (!match) return;

                    _initial = match.toString().substr(1).toLowerCase();

                    // get prefix character to pass to get()
                    _prefix = match.toString().substring(0, 1);

                    _inAutoComplete = true;
                }

                // call get() to retrieve current list of values
                var values = options.get(_prefix);
                if (values.length === 0) {
                    reset();
                    return;
                }

                _index = getNextIndex(_index, offset, values.length);

                var initialLen = _initial.length;
                // sort values if there's a prefix
                if (initialLen > 0) {
                    values = values.sort(sortInsensitive);
                }

                // loop through values (ring buffer) for match 
                var i = _index;
                while (true) {
                    var value = values[i];
                    if (value.substr(0, initialLen).toLowerCase() === _initial) {
                        var newText = _text.substr(0, _caret - initialLen) + value + _text.substr(_caret);
                        $(this).val(newText);

                        if (_caret < _text.length) {
                            setSelection(this, _caret, _caret);
                        }<commit_msg>Don't sort the input because of a prefix. Fixes #397.<commit_after>﻿; (function ($, window, document) {
    var pluginName = 'autoTabComplete',
        defaults = {
            prefixMatch: '[@]',
            values: [],
            get: function() {
                return this.values;
            }
        };

    function AutoTabComplete(element, options) {
        var element = element,
            options = $.extend({}, defaults, options),
            _defaults = defaults,
            _name = pluginName,
            _inAutoComplete,
            _text,
            _initial,
            _index,
            _caret,
            _prefix,
            _matchRegExp = new RegExp(options.prefixMatch + "\\S*$", "i"),
            Keys = { Tab: 9, Shift: 16 };

        reset();

        $(element).keydown(function (event) {
            if (event.which === Keys.Tab) {
                event.preventDefault();

                var offset = event.shiftKey ? -1 : 1;

                if (!_inAutoComplete) {
                    _text = $(this).val();
                    var sel = getSelection(this);
                    _caret = sel.end;

                    // find initial text (starts with prefix char)
                    var match = _text.substr(0, _caret).match(_matchRegExp);
                    if (!match) return;

                    _initial = match.toString().substr(1).toLowerCase();

                    // get prefix character to pass to get()
                    _prefix = match.toString().substring(0, 1);

                    _inAutoComplete = true;
                }

                // call get() to retrieve current list of values
                var values = options.get(_prefix);
                if (values.length === 0) {
                    reset();
                    return;
                }

                _index = getNextIndex(_index, offset, values.length);

                var initialLen = _initial.length;

                // loop through values (ring buffer) for match 
                var i = _index;
                while (true) {
                    var value = values[i];
                    if (value.substr(0, initialLen).toLowerCase() === _initial) {
                        var newText = _text.substr(0, _caret - initialLen) + value + _text.substr(_caret);
                        $(this).val(newText);

                        if (_caret < _text.length) {
                            setSelection(this, _caret, _caret);
                        }
{'fraction_non_alphanumeric': 0.10704500978473581, 'fraction_numerical': 0.005479452054794521, 'mean_word_length': 1.1721206969825755, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '353272', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1205, 'n_words': 318}