diff options
Diffstat (limited to 'searx/static/plugins/js/vim_hotkeys.js')
| -rw-r--r-- | searx/static/plugins/js/vim_hotkeys.js | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/searx/static/plugins/js/vim_hotkeys.js b/searx/static/plugins/js/vim_hotkeys.js index 61500d8f5..b0f265cb5 100644 --- a/searx/static/plugins/js/vim_hotkeys.js +++ b/searx/static/plugins/js/vim_hotkeys.js @@ -104,7 +104,7 @@ $(document).ready(function() { } }; - $(document).keyup(function(e) { + $(document).keydown(function(e) { // check for modifiers so we don't break browser's hotkeys if (vimKeys.hasOwnProperty(e.keyCode) && !e.ctrlKey @@ -118,12 +118,21 @@ $(document).ready(function() { } } else { if (e.target === document.body) { + e.preventDefault(); vimKeys[e.keyCode].fun(); } } } }); + function nextResult(current, direction) { + var next = current[direction](); + while (!next.is('.result') && next.length !== 0) { + next = next[direction](); + } + return next + } + function highlightResult(which) { return function() { var current = $('.result[data-vim-selected]'); @@ -156,13 +165,13 @@ $(document).ready(function() { } break; case 'down': - next = current.next('.result'); + next = nextResult(current, 'next'); if (next.length === 0) { next = $('.result:first'); } break; case 'up': - next = current.prev('.result'); + next = nextResult(current, 'prev'); if (next.length === 0) { next = $('.result:last'); } |