Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/angular-advanced-searchbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,13 @@ angular.module('angular-advanced-searchbox', [])
}
};

$scope.editNext = function(currentIndex) {
$scope.editNext = function(currentIndex, key) {
if (currentIndex === undefined)
return;

$scope.leaveEditMode(undefined, currentIndex);
if (key !== 13) {
$scope.leaveEditMode(undefined, currentIndex);
}

//TODO: check if index == array length - 1 -> what then?
if (currentIndex < $scope.searchParams.length - 1) {
Expand Down Expand Up @@ -261,19 +263,19 @@ angular.module('angular-advanced-searchbox', [])
$scope.editPrevious(searchParamIndex);
} else {
e.preventDefault();
$scope.editNext(searchParamIndex);
$scope.editNext(searchParamIndex, e.which);
}

} else if (e.which == 13) { // enter
$scope.editNext(searchParamIndex);
$scope.editNext(searchParamIndex, e.which);

} else if (e.which == 37) { // left
if (cursorPosition === 0)
$scope.editPrevious(searchParamIndex);

} else if (e.which == 39) { // right
if (cursorPosition === e.target.value.length)
$scope.editNext(searchParamIndex);
$scope.editNext(searchParamIndex, e.which);
}
};

Expand Down