From 4a9380cc95e60f17f014374afa03aac2efd3ce39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 3 Sep 2014 07:24:28 +0200 Subject: [PATCH] added limit checks to up/down arrow key selection of search results --- src/app/controllers/search.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app/controllers/search.js b/src/app/controllers/search.js index 19976cda873..6287b3fffb9 100644 --- a/src/app/controllers/search.js +++ b/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; }); };