<commit_before>// -------------------------------------------------------------------------- \\
// File: AutoCompleteView.js                                                  \\
// Module: View                                                               \\
// Requires: Core, Foundation, DOM, MenuView.js                               \\
// Author: <NAME>                                                       \\
// License: © 2010–2012 Opera Software ASA. All rights reserved.              \\
// -------------------------------------------------------------------------- \\

"use strict";

( function ( NS ) {

var AutoCompleteSource = NS.Class({

    Extends: NS.Object,

    maxResults: 10,
    suggestions: [],

    getTestFn: function ( value ) {
        var regexp = new RegExp( '\\b' + value.escapeRegExp(), 'i' );
        return regexp.test.bind( regexp );
    },
    renderSuggestion: function ( suggestion, current ) {
        return suggestion.escapeHTML();
    },
    acceptSuggestion: function ( suggestion, current ) {
        return suggestion;
    }
});

var AutoCompleteController = NS.Class({

    Extends: NS.MenuController,

    options: NS.bind( 'view.collection.childViews' ),
    selectFirst: function ( _, __, ___, options ) {
        this.focusOption( options[0] || null );
    }.observes( 'options' ),

    suggestions: function () {
        return new NS.ObservableArray();
    }.property(),

    filter: NS.bind( 'view.inputView.value' ),
    filterDidChange: function ( _, __, ___, value ) {
        var sources = this.getFromPath( 'view.sources' ),
            items = [],
            i, l, source, count, max, suggestions, accept,
            j, m, suggestion;

        if ( value.length >= this.getFromPath( 'view.minChars' ) ) {
            for ( i = 0, l = sources.length; i < l; i += 1 ) {
                source = sources[i];
                count = 0;
                max = source.get( 'maxResults' );
                suggestions = source.get( 'suggestions' );
                accept = source.getTestFn( value );

                for ( j = 0, m = suggestions.get( 'length' );
                        j < m && count < max; j += 1 ) {
                    if ( accept( suggestion = suggestions.getObjectAt( j ) ) ) {
                        items.push({<commit_msg>Set suggestions on autocomplete init.<commit_after>// -------------------------------------------------------------------------- \\
// File: AutoCompleteView.js                                                  \\
// Module: View                                                               \\
// Requires: Core, Foundation, DOM, MenuView.js                               \\
// Author: <NAME>                                                       \\
// License: © 2010–2012 Opera Software ASA. All rights reserved.              \\
// -------------------------------------------------------------------------- \\

"use strict";

( function ( NS ) {

var AutoCompleteSource = NS.Class({

    Extends: NS.Object,

    maxResults: 10,
    suggestions: [],

    getTestFn: function ( value ) {
        var regexp = new RegExp( '\\b' + value.escapeRegExp(), 'i' );
        return regexp.test.bind( regexp );
    },
    renderSuggestion: function ( suggestion, current ) {
        return suggestion.escapeHTML();
    },
    acceptSuggestion: function ( suggestion, current ) {
        return suggestion;
    }
});

var AutoCompleteController = NS.Class({

    Extends: NS.MenuController,

    init: function ( options ) {
        AutoCompleteController.parent.init.call( this, options );
        this.filterDidChange( null, '', '', this.get( 'filter' ) );
    },

    options: NS.bind( 'view.collection.childViews' ),
    selectFirst: function ( _, __, ___, options ) {
        this.focusOption( options[0] || null );
    }.observes( 'options' ),

    suggestions: function () {
        return new NS.ObservableArray();
    }.property(),

    filter: NS.bind( 'view.inputView.value' ),
    filterDidChange: function ( _, __, ___, value ) {
        var sources = this.getFromPath( 'view.sources' ),
            items = [],
            i, l, source, count, max, suggestions, accept,
            j, m, suggestion;

        if ( value.length >= this.getFromPath( 'view.minChars' ) ) {
            for ( i = 0, l = sources.length; i < l; i += 1 ) {
                source = sources[i];
                count = 0;
                max = source.get( 'maxResults' );
                suggestions = source.get( 'suggestions' );
                accept = source.getTestFn( value );

                for ( j = 0, m = suggestions.get( 'length' );
                        j < m && count < max; j += 1 ) {
                    if ( accept( suggestion = suggestions.getObjectAt( j ) ) ) {
                        items.push({
{'fraction_non_alphanumeric': 0.18587205667847467, 'fraction_numerical': 0.006668055844967702, 'mean_word_length': 1.2933588150979456, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6640379', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1166, 'n_words': 303}