mirror of
https://github.com/searxng/searxng.git
synced 2024-11-04 20:30:11 +01:00
[feature] key bindings: left & right arrow are always on
This commit is contained in:
parent
b189578b6b
commit
e6b160da62
@ -55,13 +55,30 @@ searxng.ready(function () {
|
||||
}
|
||||
}, true);
|
||||
|
||||
var vimKeys = {
|
||||
// these bindings are always on
|
||||
var keyBindings = {
|
||||
27: {
|
||||
key: 'Escape',
|
||||
fun: removeFocus,
|
||||
des: 'remove focus from the focused input',
|
||||
cat: 'Control'
|
||||
},
|
||||
37: {
|
||||
key: 'Left',
|
||||
fun: ifDetailOpened(highlightResult('up')),
|
||||
des: 'select previous search result',
|
||||
cat: 'Results'
|
||||
},
|
||||
39: {
|
||||
key: 'Right',
|
||||
fun: ifDetailOpened(highlightResult('down')),
|
||||
des: 'select next search result',
|
||||
cat: 'Results'
|
||||
}
|
||||
}
|
||||
|
||||
// these bindings are enabled by user preferences
|
||||
var vimKeys = {
|
||||
73: {
|
||||
key: 'i',
|
||||
fun: searchInputFocus,
|
||||
@ -155,20 +172,31 @@ searxng.ready(function () {
|
||||
};
|
||||
|
||||
if (searxng.settings.hotkeys) {
|
||||
searxng.on(document, "keydown", function (e) {
|
||||
// check for modifiers so we don't break browser's hotkeys
|
||||
if (Object.prototype.hasOwnProperty.call(vimKeys, e.keyCode) && !e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey) {
|
||||
var tagName = e.target.tagName.toLowerCase();
|
||||
if (e.keyCode === 27) {
|
||||
vimKeys[e.keyCode].fun(e);
|
||||
} else {
|
||||
if (e.target === document.body || tagName === 'a' || tagName === 'button') {
|
||||
e.preventDefault();
|
||||
vimKeys[e.keyCode].fun();
|
||||
}
|
||||
// To add Vim-like key bindings, merge the 'vimKeys' into 'keyBindings'.
|
||||
Object.assign(keyBindings, vimKeys);
|
||||
}
|
||||
|
||||
searxng.on(document, "keydown", function (e) {
|
||||
// check for modifiers so we don't break browser's hotkeys
|
||||
if (Object.prototype.hasOwnProperty.call(keyBindings, e.keyCode) && !e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey) {
|
||||
var tagName = e.target.tagName.toLowerCase();
|
||||
if (e.keyCode === 27) {
|
||||
keyBindings[e.keyCode].fun(e);
|
||||
} else {
|
||||
if (e.target === document.body || tagName === 'a' || tagName === 'button') {
|
||||
e.preventDefault();
|
||||
keyBindings[e.keyCode].fun();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function ifDetailOpened (f) {
|
||||
return function () {
|
||||
if (searxng.isDetailOpened()) {
|
||||
f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function highlightResult (which) {
|
||||
@ -347,8 +375,8 @@ searxng.ready(function () {
|
||||
function initHelpContent (divElement) {
|
||||
var categories = {};
|
||||
|
||||
for (var k in vimKeys) {
|
||||
var key = vimKeys[k];
|
||||
for (var k in keyBindings) {
|
||||
var key = keyBindings[k];
|
||||
categories[key.cat] = categories[key.cat] || [];
|
||||
categories[key.cat].push(key);
|
||||
}
|
||||
|
@ -74,6 +74,10 @@
|
||||
searxng.scrollPageToSelected();
|
||||
}
|
||||
|
||||
searxng.isDetailOpened = function () {
|
||||
return d.getElementById('results').classList.contains('image-detail-open');
|
||||
}
|
||||
|
||||
searxng.closeDetail = function (e) {
|
||||
d.getElementById('results').classList.remove('image-detail-open');
|
||||
searxng.scrollPageToSelected();
|
||||
|
Loading…
Reference in New Issue
Block a user