Просмотр исходного кода

added limit checks to up/down arrow key selection of search results

Torkel Ödegaard 11 лет назад
Родитель
Сommit
4a9380cc95
1 измененных файлов с 7 добавлено и 2 удалено
  1. 7 2
      src/app/controllers/search.js

+ 7 - 2
src/app/controllers/search.js

@@ -31,10 +31,10 @@ function (angular, _, config, $) {
         $scope.emitAppEvent('hide-dash-editor');
       }
       if (evt.keyCode === 40) {
-        $scope.selectedIndex++;
+        $scope.moveSelection(1);
       }
       if (evt.keyCode === 38) {
-        $scope.selectedIndex--;
+        $scope.moveSelection(-1);
       }
       if (evt.keyCode === 13) {
         if ($scope.tagsOnly) {
@@ -56,6 +56,10 @@ function (angular, _, config, $) {
       }
     };
 
+    $scope.moveSelection = function(direction) {
+      $scope.selectedIndex = Math.max(Math.min($scope.selectedIndex + direction, $scope.resultCount - 1), 0);
+    };
+
     $scope.goToDashboard = function(id) {
       $location.path("/dashboard/db/" + id);
     };
@@ -76,6 +80,7 @@ function (angular, _, config, $) {
           $scope.tagsOnly = results.tagsOnly;
           $scope.results.dashboards = results.dashboards;
           $scope.results.tags = results.tags;
+          $scope.resultCount = results.tagsOnly ? results.tags.length : results.dashboards.length;
         });
     };