[mod] reformatted keyBindingLayouts in JS client (default, vim)

This commit is contained in:
Jinyuan Huang 2023-09-16 10:40:59 +00:00 committed by Markus Heiser
parent 317db5b04f
commit 2ec77ef813
1 changed files with 72 additions and 69 deletions

View File

@ -55,26 +55,14 @@ searxng.ready(function () {
} }
}, true); }, true);
// these bindings are always on /* common base for layouts */
var keyBindings = { var baseKeyBinding = {
'Escape': { 'Escape': {
key: 'ESC', key: 'ESC',
fun: removeFocus, fun: removeFocus,
des: 'remove focus from the focused input', des: 'remove focus from the focused input',
cat: 'Control' 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': { 'h': {
key: 'h', key: 'h',
fun: toggleHelp, fun: toggleHelp,
@ -117,10 +105,27 @@ searxng.ready(function () {
des: 'open the result in a new tab', des: 'open the result in a new tab',
cat: 'Results' cat: 'Results'
}, },
} };
var keyBindingLayouts = {
// these bindings are enabled by user preferences "default": Object.assign(
var vimKeys = { { /* 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': { 'b': {
key: 'b', key: 'b',
fun: scrollPage(-window.innerHeight), fun: scrollPage(-window.innerHeight),
@ -169,13 +174,11 @@ searxng.ready(function () {
des: 'select next search result', des: 'select next search result',
cat: 'Results' cat: 'Results'
}, },
}; }, baseKeyBinding)
if (searxng.settings.hotkeys) {
// To add Vim-like key bindings, merge the 'vimKeys' into 'keyBindings'.
Object.assign(keyBindings, vimKeys);
} }
var keyBindings = keyBindingLayouts[searxng.settings.hotkeys] || keyBindingLayouts.default;
searxng.on(document, "keydown", function (e) { searxng.on(document, "keydown", function (e) {
// check for modifiers so we don't break browser's hotkeys // check for modifiers so we don't break browser's hotkeys
if ( if (