From 2ec77ef813aec1aec7cd08d1130b5e90a03cf760 Mon Sep 17 00:00:00 2001 From: Jinyuan Huang <88757735+BernieHuang2008@users.noreply.github.com> Date: Sat, 16 Sep 2023 10:40:59 +0000 Subject: [PATCH] [mod] reformatted keyBindingLayouts in JS client (default, vim) --- .../themes/simple/src/js/main/keyboard.js | 143 +++++++++--------- 1 file changed, 73 insertions(+), 70 deletions(-) diff --git a/searx/static/themes/simple/src/js/main/keyboard.js b/searx/static/themes/simple/src/js/main/keyboard.js index 5c02acbfd..d29518358 100644 --- a/searx/static/themes/simple/src/js/main/keyboard.js +++ b/searx/static/themes/simple/src/js/main/keyboard.js @@ -55,26 +55,14 @@ searxng.ready(function () { } }, true); - // these bindings are always on - var keyBindings = { + /* common base for layouts */ + var baseKeyBinding = { 'Escape': { key: 'ESC', fun: removeFocus, des: 'remove focus from the focused input', cat: 'Control' }, - 'ArrowLeft': { - key: '⬅', - fun: highlightResult('up'), - des: 'Use left arrow to select previous search result', - cat: 'Results' - }, - 'ArrowRight': { - key: '➡', - fun: highlightResult('down'), - des: 'Use right arrow to select next search result', - cat: 'Results' - }, 'h': { key: 'h', fun: toggleHelp, @@ -117,65 +105,80 @@ searxng.ready(function () { des: 'open the result in a new tab', cat: 'Results' }, - } - - // these bindings are enabled by user preferences - var vimKeys = { - 'b': { - key: 'b', - fun: scrollPage(-window.innerHeight), - des: 'scroll one page up', - cat: 'Navigation' - }, - 'f': { - key: 'f', - fun: scrollPage(window.innerHeight), - des: 'scroll one page down', - cat: 'Navigation' - }, - 'u': { - key: 'u', - fun: scrollPage(-window.innerHeight / 2), - des: 'scroll half a page up', - cat: 'Navigation' - }, - 'd': { - key: 'd', - fun: scrollPage(window.innerHeight / 2), - des: 'scroll half a page down', - cat: 'Navigation' - }, - 'g': { - key: 'g', - fun: scrollPageTo(-document.body.scrollHeight, 'top'), - des: 'scroll to the top of the page', - cat: 'Navigation' - }, - 'v': { - key: 'v', - fun: scrollPageTo(document.body.scrollHeight, 'bottom'), - des: 'scroll to the bottom of the page', - cat: 'Navigation' - }, - 'k': { - key: 'k', - fun: highlightResult('up'), - des: 'select previous search result', - cat: 'Results' - }, - 'j': { - key: 'j', - fun: highlightResult('down'), - des: 'select next search result', - cat: 'Results' - }, }; - - if (searxng.settings.hotkeys) { - // To add Vim-like key bindings, merge the 'vimKeys' into 'keyBindings'. - Object.assign(keyBindings, vimKeys); + var keyBindingLayouts = { + + "default": Object.assign( + { /* SearXNG layout */ + 'ArrowLeft': { + key: '←', + fun: highlightResult('up'), + des: 'select previous search result', + cat: 'Results' + }, + 'ArrowRight': { + key: '→', + fun: highlightResult('down'), + des: 'select next search result', + cat: 'Results' + }, + }, baseKeyBinding), + + 'vim': Object.assign( + { /* Vim-like Key Layout. */ + 'b': { + key: 'b', + fun: scrollPage(-window.innerHeight), + des: 'scroll one page up', + cat: 'Navigation' + }, + 'f': { + key: 'f', + fun: scrollPage(window.innerHeight), + des: 'scroll one page down', + cat: 'Navigation' + }, + 'u': { + key: 'u', + fun: scrollPage(-window.innerHeight / 2), + des: 'scroll half a page up', + cat: 'Navigation' + }, + 'd': { + key: 'd', + fun: scrollPage(window.innerHeight / 2), + des: 'scroll half a page down', + cat: 'Navigation' + }, + 'g': { + key: 'g', + fun: scrollPageTo(-document.body.scrollHeight, 'top'), + des: 'scroll to the top of the page', + cat: 'Navigation' + }, + 'v': { + key: 'v', + fun: scrollPageTo(document.body.scrollHeight, 'bottom'), + des: 'scroll to the bottom of the page', + cat: 'Navigation' + }, + 'k': { + key: 'k', + fun: highlightResult('up'), + des: 'select previous search result', + cat: 'Results' + }, + 'j': { + key: 'j', + fun: highlightResult('down'), + des: 'select next search result', + cat: 'Results' + }, + }, baseKeyBinding) } + var keyBindings = keyBindingLayouts[searxng.settings.hotkeys] || keyBindingLayouts.default; + searxng.on(document, "keydown", function (e) { // check for modifiers so we don't break browser's hotkeys if (