Skip to content

Commit

Permalink
Wrap around when navigating CPE suggestions via arrow keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ra1nb0rn committed Sep 2, 2024
1 parent b1d9185 commit 4c0f556
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions web_server_files/static/js/search_vulns.js
Original file line number Diff line number Diff line change
Expand Up @@ -1114,9 +1114,11 @@ function moveCPESuggestionUpDown(event) {
else if (event.keyCode == 40)
curSelectedCPESuggestion++;

// enforce lower and upper bounds
curSelectedCPESuggestion = Math.max(-1, curSelectedCPESuggestion);
curSelectedCPESuggestion = Math.min(curSelectedCPESuggestion, $("#cpeSuggestions").find('ul').children('li').length - 1);
// wrap around if moving below available suggestions or above them
if (curSelectedCPESuggestion < 0)
curSelectedCPESuggestion = $("#cpeSuggestions").find('ul').children('li').length - 1;
else if (curSelectedCPESuggestion > $("#cpeSuggestions").find('ul').children('li').length - 1)
curSelectedCPESuggestion = 0;

if (curSelectedCPESuggestion > -1) {
const suggestionElement = $('#cpe-suggestion-' + curSelectedCPESuggestion);
Expand Down

0 comments on commit 4c0f556

Please sign in to comment.