<commit_before>(function() {
    angular.module('hint', [])
        .directive('hint', function() {
            return {
                restrict: 'E',
                scope: {
                    info: '='
                },
                templateUrl: 'hint.html',
                controller: ['$scope', '$http', function($scope, $http) {
                    $scope.list = [];

                    $scope.selected = -1;

                    $scope.attach = function(idx) {
                        $scope.info.q = $scope.list[idx];
                    }

                    $scope.mouseover = function(idx) {
                        $scope.selected = idx;
                        $scope.attach($scope.selected);
                    }

                    $scope.keydown = function(e) {
                        switch (e.keyCode) {
                            case 38:
                                e.preventDefault();

                                $scope.selected--;
                                if($scope.selected < 0);
                                    $scope.selected = $scope.list.length - 1;

                                $scope.attach($scope.selected);
                                break;
                            case 40:
                                e.preventDefault();
                                
                                $scope.selected++;
                                if($scope.selected == $scope.list.length)
                                    $scope.selected = 0;
                                
                                $scope.attach($scope.selected);
                                break;
                            case 13:
                                $scope.list = [];
                                break;
                        }
                    }

                    $scope.click = function(idx){
                        $scope.attach(idx);
                        $scope.list = []; 
                    }

                    $scope.search = function(query) {
                        $scope.list = $scope.info.fetch(query);
                    }
                }]
            }
        })
})();
<commit_msg>fix the bug when there is only one item in the list, it can't attach when press enter<commit_after>(function() {
    angular.module('hint', [])
        .directive('hint', function() {
            return {
                restrict: 'E',
                scope: {
                    info: '='
                },
                templateUrl: 'hint.html',
                controller: ['$scope', '$http', function($scope, $http) {
                    $scope.list = [];

                    $scope.selected = -1;

                    $scope.attach = function(idx) {
                        $scope.info.q = $scope.list[idx];
                    }

                    $scope.mouseover = function(idx) {
                        $scope.selected = idx;
                        $scope.attach($scope.selected);
                    }

                    $scope.keydown = function(e) {
                        switch (e.keyCode) {
                            case 38:
                                e.preventDefault();

                                $scope.selected--;
                                if($scope.selected < 0);
                                    $scope.selected = $scope.list.length - 1;

                                $scope.attach($scope.selected);
                                break;
                            case 40:
                                e.preventDefault();
                                
                                $scope.selected++;
                                if($scope.selected == $scope.list.length)
                                    $scope.selected = 0;
                                
                                $scope.attach($scope.selected);
                                break;
                            case 13:
                                $scope.list = [];
                                $scope.selected = -1;
                                break;
                        }
                    }

                    $scope.click = function(idx){
                        $scope.attach(idx);
                        $scope.list = []; 
                        $scope.selected = -1;
                    }

                    $scope.search = function(query) {
                        $scope.list = $scope.info.fetch(query);
                    }
                }]
            }
        })
})();

{'fraction_non_alphanumeric': 0.10320597277119016, 'fraction_numerical': 0.004830917874396135, 'mean_word_length': 0.6267857142857143, 'pattern_counts': {'":': 0, '<': 5, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '163469', 'n_tokens_mistral': 1026, 'n_tokens_neox': 908, 'n_words': 151}