[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);
// 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,10 +105,27 @@ searxng.ready(function () {
des: 'open the result in a new tab',
cat: 'Results'
},
}
};
var keyBindingLayouts = {
// these bindings are enabled by user preferences
var vimKeys = {
"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),
@ -169,13 +174,11 @@ searxng.ready(function () {
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);
}, 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 (