Files
zulip/static/js/keydown_util.js
aryanshridhar 9f9259683c settings_panel: Bind vim keys to SettingsPanelMenu.
Added a commit to bind vim keys with the SettingsPanelMenu,
allowing users to control the settings and organization tabs
using 'h','j','k' and 'l' keys.

vim_left('h') -> Switch between tab by shifting focus to the left.
vim_right('l') -> Switch between tab by shifting focus to the right.
vim_up('k') -> Move up.
vim_down('j') -> Move down.
2021-05-10 17:30:10 -07:00

43 lines
785 B
JavaScript

/*
See hotkey.js for handlers that are more app-wide.
*/
const keys = {
13: "enter_key",
37: "left_arrow",
38: "up_arrow",
39: "right_arrow",
40: "down_arrow",
72: "vim_left",
74: "vim_down",
75: "vim_up",
76: "vim_right",
};
export function handle(opts) {
opts.elem.on("keydown", (e) => {
const key = e.which || e.keyCode;
if (e.altKey || e.ctrlKey || e.shiftKey) {
return;
}
const key_name = keys[key];
if (!key_name) {
return;
}
if (!opts.handlers[key_name]) {
return;
}
const handled = opts.handlers[key_name]();
if (handled) {
e.preventDefault();
e.stopPropagation();
}
});
}