Commit 4a9380cc by Torkel Ödegaard

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

parent 9f60745e
......@@ -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;
});
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment