<commit_before>import React, {Component} from 'react';

class Select extends Component {

    state = {
        items: [],
        value: this.props.value,
        selectedIndex: -1,
        isAutocompleteOpen: false,
    };

    search = text => new Promise(resolve => resolve([text]));
    getSuggestionValue = item => item;

    _showAC = () => this.setState({isAutocompleteOpen: true});
    _hideAC = () => this.setState({isAutocompleteOpen: false});

    render() {
        let {onFocus, onBlur, onChange, onKeyPress, onKeyDown, onMouseDown, onError, onSelect, ...rest} = this.props;
        let {items, value, selectedIndex, isAutocompleteOpen} = this.state;
        return (
            <div>
                {this.renderInput({
                    ...rest,
                    value,
                    onFocus: e => {
                        this._showAC();
                        onFocus(e);
                    },
                    onBlur: e => {
                        this._hideAC();
                        onBlur(e);
                    },
                    onChange: e => {
                        this.setState({value: e.target.value});
                        this.search(e.target.value)
                            .then(items => this.setState({items}))
                            .catch(onError);
                        onChange(e)
                    },
                    onKeyPress: e => {
                        this.setState({value});
                        onKeyPress(e);
                    },
                    onKeyDown: e => {
                        let value;
                        if (!isAutocompleteOpen) {
                            this._showAC();
                        }

                        // Arrow down
                        if (e.which === 40) {
                            if (selectedIndex < items.length - 1) {
                                e.preventDefault();
                                this.setState({selectedIndex: selectedIndex + 1});
                            }
                        }

                        // Arrow up
                        if (e.which === 38) {
                            if (selectedIndex > 0) {
                                e.preventDefault();
                                this.setState({selectedIndex: selectedIndex - 1});
                            }
                            if (selectedIndex < 0) {
                                e.preventDefault();
                                this.setState({selectedIndex: items.length - 1});
                            }
                        }

                        // Enter
                        if (e.which === 13) {
                            if (selectedIndex >= 0 || selectedIndex < items.length) {
                                value = this.getSuggestionValue(items[selectedIndex]);
                                this.setState({value, isAutocompleteOpen: false});
                                onSelect(value)
                            }
                        }

                        // Escape
                        if (e.which === 27) {
                            this._hideAC();
                        }

                        this.setState({value});
                        onKeyDown(e);
                    },
                    onMouseDown: e => {
                        this.setState({value});
                        if (!isAutocompleteOpen) {
                            this._showAC();
                        }
                        onMouseDown(e);
                    },
                })}
                {isAutocompleteOpen ? this.renderAutocomplete({
                    getItemValue: this.getSuggestionValue,
                    items,
                    selectedIndex,
                    renderItem: this.renderAutocompleteItem,
                    value,
                    onSelect: value => {
                        this.setState({value});
                        onSelect(value)
                    },
                }) : null}
            </div>
        );
    }
}
Select.defaultProps = {
    value: '',
    onSelect: () => {},
    onFocus: () => {},
    onBlur: () => {},
    onChange: () => {},
    onKeyPress: () => {},
    onKeyDown: () => {},<commit_msg>Update Select.js<commit_after>import React, {Component} from 'react';

class Select extends Component {

    state = {
        items: [],
        value: this.props.value,
        selectedIndex: -1,
        isAutocompleteOpen: false,
    };

    search = text => new Promise(resolve => resolve([text]));
    getSuggestionText = item => item;
    getSuggestionValue = item => item;

    _showAC = () => this.setState({isAutocompleteOpen: true});
    _hideAC = () => this.setState({isAutocompleteOpen: false});

    render() {
        let {onFocus, onBlur, onChange, onKeyPress, onKeyDown, onMouseDown, onError, onSelect, ...rest} = this.props;
        let {items, value, selectedIndex, isAutocompleteOpen} = this.state;
        return (
            <div>
                {this.renderInput({
                    ...rest,
                    value,
                    onFocus: e => {
                        this._showAC();
                        onFocus(e);
                    },
                    onBlur: e => {
                        this._hideAC();
                        onBlur(e);
                    },
                    onChange: e => {
                        this.setState({value: e.target.value});
                        this.search(e.target.value)
                            .then(items => this.setState({items}))
                            .catch(onError);
                        onChange(e)
                    },
                    onKeyPress: e => {
                        this.setState({value});
                        onKeyPress(e);
                    },
                    onKeyDown: e => {
                        let value;
                        if (!isAutocompleteOpen) {
                            this._showAC();
                        }

                        // Arrow down
                        if (e.which === 40) {
                            if (selectedIndex < items.length - 1) {
                                e.preventDefault();
                                this.setState({selectedIndex: selectedIndex + 1});
                            }
                        }

                        // Arrow up
                        if (e.which === 38) {
                            if (selectedIndex > 0) {
                                e.preventDefault();
                                this.setState({selectedIndex: selectedIndex - 1});
                            }
                            if (selectedIndex < 0) {
                                e.preventDefault();
                                this.setState({selectedIndex: items.length - 1});
                            }
                        }

                        // Enter
                        if (e.which === 13) {
                            if (selectedIndex >= 0 || selectedIndex < items.length) {
                                value = this.getSuggestionValue(items[selectedIndex]);
                                this.setState({value, isAutocompleteOpen: false});
                                onSelect(value)
                            }
                        }

                        // Escape
                        if (e.which === 27) {
                            this._hideAC();
                        }

                        this.setState({value});
                        onKeyDown(e);
                    },
                    onMouseDown: e => {
                        this.setState({value});
                        if (!isAutocompleteOpen) {
                            this._showAC();
                        }
                        onMouseDown(e);
                    },
                })}
                {isAutocompleteOpen ? this.renderAutocomplete({
                    getItemText: this.getSuggestionText,
                    getItemValue: this.getSuggestionValue,
                    items,
                    selectedIndex,
                    renderItem: this.renderAutocompleteItem,
                    value,
                    onSelect: value => {
                        this.setState({value});
                        onSelect(value)
                    },
                }) : null}
            </div>
        );
    }
}
Select.defaultProps = {
    value: '',
    onSelect: () => {},
    onFocus: () => {},
    onBlur: () => {},
    onChange: () => {},
    onKeyPress: () => {},
    onKeyDown: () => {},
{'fraction_non_alphanumeric': 0.10550564386086156, 'fraction_numerical': 0.0036857866850956, 'mean_word_length': 0.7966066625284502, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 50, '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': '3570258', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1849, 'n_words': 338}