<commit_before>(function() {
    "use strict";

    var suggestBox;
    var appended = false;
    var selectedIndex = 0;
    var numOptions = 0;
    var hideTillNextFocus = false;
    var options;
    var currentInput;
    var shouldSuggest = true;

    function fillOptions(opts) {
        suggestBox.html("");
        numOptions = 0;
        opts.forEach(function(option) {
            var newEl = $("<div class='suggestOption'>");
            newEl.text(option);
            newEl.on("mousedown", function() {
                currentInput.val($(this).text());
            });
            suggestBox.append(newEl);
            options = suggestBox.find("div");
            ++numOptions;
        });
    };

    function init() {
        if (!suggestBox) {
            suggestBox = $("<div class='suggestBox'>");
        }

        var inputs = $("input[data-suggest]");

        var keyUpFunc = function(e) {
            if (shouldSuggest) {
                var code = e.which;
                if ((code < 37 || code > 40) && code !== 13) {
                    // not the arrow keys or enter or ESC.
                    filterOptions($(this).val());
                }
            }
        };

        inputs.off("focus keydown blur");
        inputs.off("keyup", keyUpFunc);

        inputs.on("focus", function() {
            if (shouldSuggest) {
                var input = $(this);
                var offset = input.offset();
                hideTillNextFocus = false;
                currentInput = input;
                suggestBox.css({
                    top: offset.top + input.height() + 5 + "px",
                    left: offset.left + "px",
                    maxWidth: input.width() + 6 + "px"
                });
                show();
                selectedIndex = 0;
                filterOptions(input.val());
            }
        });

        inputs.on("keydown", function(e) {
            if (shouldSuggest) {
                var code = e.which;
                if (code === 38) { // UP
                    e.preventDefault();
                    selectUp(true);
                }
                if (code === 40) { // DOWN
                    e.preventDefault();
                    selectDown(true);
                }
                if (code === 13) { // Enter
                    $(this).val(options.eq(selectedIndex).text());
                    suggestBox.hide();
                }
                if (code === 27) { // ESC
                    suggestBox.hide();
                    hideTillNextFocus = true;
                }
                highlightOption();
            }
        });

        inputs.on("keyup", keyUpFunc);

        inputs.on("blur", function() {
            suggestBox.hide();
        });

        if (!appended) {
            $("body").append(suggestBox);
            appended = true;
        }
    };

    function show() {
        if (!hideTillNextFocus) {
            suggestBox.show();
        }
    }

    function filterOptions(inputVal) {<commit_msg>Make suggest feature only autocomplete what's needed.<commit_after>(function() {
    "use strict";

    var suggestBox;
    var appended = false;
    var selectedIndex = 0;
    var numOptions = 0;
    var hideTillNextFocus = false;
    var options;
    var currentInput;
    var shouldSuggest = true;

    function fillOptions(opts) {
        suggestBox.html("");
        numOptions = 0;
        opts.forEach(function(option) {
            var newEl = $("<div class='suggestOption'>");
            newEl.text(option);
            newEl.on("mousedown", function() {
                completeInput(currentInput, $(this));
            });
            suggestBox.append(newEl);
            options = suggestBox.find("div");
            ++numOptions;
        });
    };

    function init() {
        if (!suggestBox) {
            suggestBox = $("<div class='suggestBox'>");
        }

        var inputs = $("input[data-suggest]");

        var keyUpFunc = function(e) {
            if (shouldSuggest) {
                var code = e.which;
                if ((code < 37 || code > 40) && code !== 13) {
                    // not the arrow keys or enter or ESC.
                    filterOptions($(this).val());
                }
            }
        };

        inputs.off("focus keydown blur");
        inputs.off("keyup", keyUpFunc);

        inputs.on("focus", function() {
            if (shouldSuggest) {
                var input = $(this);
                var offset = input.offset();
                hideTillNextFocus = false;
                currentInput = input;
                suggestBox.css({
                    top: offset.top + input.height() + 5 + "px",
                    left: offset.left + "px",
                    maxWidth: input.width() + 6 + "px"
                });
                show();
                selectedIndex = 0;
                filterOptions(input.val());
            }
        });

        inputs.on("keydown", function(e) {
            if (shouldSuggest) {
                var code = e.which;
                if (code === 38) { // UP
                    e.preventDefault();
                    selectUp(true);
                }
                if (code === 40) { // DOWN
                    e.preventDefault();
                    selectDown(true);
                }
                if (code === 13) { // Enter
                    completeInput($(this));
                    suggestBox.hide();
                }
                if (code === 27) { // ESC
                    suggestBox.hide();
                    hideTillNextFocus = true;
                }
                highlightOption();
            }
        });

        inputs.on("keyup", keyUpFunc);

        inputs.on("blur", function() {
            suggestBox.hide();
        });

        if (!appended) {
            $("body").append(suggestBox);
            appended = true;
        }
    };

    function show() {
        if (!hideTillNextFocus) {
            suggestBox.show();
        }
    }



    function completeInput(input, option) {
        var selectedText = option ? option.text() : options.eq(selectedIndex).text();
        var inputParts = input.val().split("*");
        var lastPart = inputParts[inputParts.length - 1];
        var lastIndex = selectedText.lastIndexOf(lastPart);
        input.val(input.val() + selectedText.substring(lastIndex + lastPart.length));
    }

    function filterOptions(inputVal) {
{'fraction_non_alphanumeric': 0.1307990690457719, 'fraction_numerical': 0.006361520558572537, 'mean_word_length': 1.2436477549599723, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '852156', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1603, 'n_words': 352}