summaryrefslogtreecommitdiff
path: root/searx/static
diff options
context:
space:
mode:
authorJinyuan Huang <88757735+BernieHuang2008@users.noreply.github.com>2023-09-16 10:40:59 +0000
committerMarkus Heiser <markus.heiser@darmarIT.de>2023-09-19 08:06:06 +0200
commit2ec77ef813aec1aec7cd08d1130b5e90a03cf760 (patch)
tree338f9275910ff117343bd9cb461b9705c7911abe /searx/static
parent317db5b04f6de919e996df943f7f0a845b8238a9 (diff)
downloadsearxng-2ec77ef813aec1aec7cd08d1130b5e90a03cf760.tar.gz
searxng-2ec77ef813aec1aec7cd08d1130b5e90a03cf760.zip
[mod] reformatted keyBindingLayouts in JS client (default, vim)
Diffstat (limited to 'searx/static')
-rw-r--r--searx/static/themes/simple/src/js/main/keyboard.js143
1 files 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: '&#11013;',
- fun: highlightResult('up'),
- des: 'Use left arrow to select previous search result',
- cat: 'Results'
- },
- 'ArrowRight': {
- key: '&#10145;',
- 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 (