mirror of https://github.com/zulip/zulip.git
recent_topics: Add support for vim keys.
User can now user `j`, `k`, `l`, `h` keys to navigate along with arrow keys, which is inline with our message navigation hotkeys.
This commit is contained in:
parent
b34d46e00b
commit
08701d0287
|
@ -196,7 +196,7 @@ run_test("basic_chars", () => {
|
|||
|
||||
// Unmapped keys should immediately return false, without
|
||||
// calling any functions outside of hotkey.js.
|
||||
assert_unmapped("abfhlmoyz");
|
||||
assert_unmapped("abfmoyz");
|
||||
assert_unmapped("BEFHILNOQTUWXYZ");
|
||||
|
||||
// We have to skip some checks due to the way the code is
|
||||
|
@ -236,6 +236,7 @@ run_test("basic_chars", () => {
|
|||
is_active,
|
||||
settings_open,
|
||||
info_overlay_open,
|
||||
recent_topics_open: return_false,
|
||||
});
|
||||
test_normal_typing();
|
||||
}
|
||||
|
|
|
@ -96,9 +96,11 @@ const keypress_mappings = {
|
|||
100: {name: "open_drafts", message_view_only: true}, // 'd'
|
||||
101: {name: "edit_message", message_view_only: true}, // 'e'
|
||||
103: {name: "gear_menu", message_view_only: true}, // 'g'
|
||||
104: {name: "vim_left", message_view_only: true}, // 'h'
|
||||
105: {name: "message_actions", message_view_only: true}, // 'i'
|
||||
106: {name: "vim_down", message_view_only: true}, // 'j'
|
||||
107: {name: "vim_up", message_view_only: true}, // 'k'
|
||||
108: {name: "vim_right", message_view_only: true}, // 'l'
|
||||
110: {name: "n_key", message_view_only: false}, // 'n'
|
||||
112: {name: "p_key", message_view_only: false}, // 'p'
|
||||
113: {name: "query_streams", message_view_only: true}, // 'q'
|
||||
|
@ -427,6 +429,10 @@ exports.process_hotkey = function (e, hotkey) {
|
|||
case "down_arrow":
|
||||
case "left_arrow":
|
||||
case "right_arrow":
|
||||
case "vim_up":
|
||||
case "vim_down":
|
||||
case "vim_left":
|
||||
case "vim_right":
|
||||
case "tab":
|
||||
case "shift_tab":
|
||||
if (overlays.recent_topics_open()) {
|
||||
|
|
|
@ -464,12 +464,6 @@ exports.change_focused_element = function (e, input_key) {
|
|||
// returning true will cause the caller to do
|
||||
// preventDefault/stopPropagation; false will let the browser
|
||||
// handle the key.
|
||||
if (input_key === "tab") {
|
||||
input_key = "right_arrow";
|
||||
} else if (input_key === "shift_tab") {
|
||||
input_key = "left_arrow";
|
||||
}
|
||||
|
||||
const $elem = $(e.target);
|
||||
|
||||
if ($("#recent_topics_table").find(":focus").length === 0) {
|
||||
|
@ -493,12 +487,23 @@ exports.change_focused_element = function (e, input_key) {
|
|||
}
|
||||
|
||||
switch (input_key) {
|
||||
case "vim_left":
|
||||
case "vim_right":
|
||||
case "vim_down":
|
||||
case "vim_up":
|
||||
return false;
|
||||
case "shift_tab":
|
||||
current_focus_elem = filter_buttons().last();
|
||||
break;
|
||||
case "left_arrow":
|
||||
if (start !== 0 || is_selected) {
|
||||
return false;
|
||||
}
|
||||
current_focus_elem = filter_buttons().last();
|
||||
break;
|
||||
case "tab":
|
||||
current_focus_elem = filter_buttons().first();
|
||||
break;
|
||||
case "right_arrow":
|
||||
if (end !== text_length || is_selected) {
|
||||
return false;
|
||||
|
@ -520,6 +525,8 @@ exports.change_focused_element = function (e, input_key) {
|
|||
}
|
||||
} else if ($elem.hasClass("btn-recent-filters")) {
|
||||
switch (input_key) {
|
||||
case "shift_tab":
|
||||
case "vim_left":
|
||||
case "left_arrow":
|
||||
if (filter_buttons().first()[0] === $elem[0]) {
|
||||
current_focus_elem = $("#recent_topics_search");
|
||||
|
@ -527,6 +534,8 @@ exports.change_focused_element = function (e, input_key) {
|
|||
current_focus_elem = $elem.prev();
|
||||
}
|
||||
break;
|
||||
case "tab":
|
||||
case "vim_right":
|
||||
case "right_arrow":
|
||||
if (filter_buttons().last()[0] === $elem[0]) {
|
||||
current_focus_elem = $("#recent_topics_search");
|
||||
|
@ -534,6 +543,7 @@ exports.change_focused_element = function (e, input_key) {
|
|||
current_focus_elem = $elem.next();
|
||||
}
|
||||
break;
|
||||
case "vim_down":
|
||||
case "down_arrow":
|
||||
set_table_focus(row_focus, col_focus);
|
||||
return true;
|
||||
|
@ -543,21 +553,27 @@ exports.change_focused_element = function (e, input_key) {
|
|||
// wraparound. Going off the top or the bottom takes one
|
||||
// to the navigation at the top (see set_table_focus).
|
||||
switch (input_key) {
|
||||
case "shift_tab":
|
||||
case "vim_left":
|
||||
case "left_arrow":
|
||||
col_focus -= 1;
|
||||
if (col_focus < 0) {
|
||||
col_focus = MAX_SELECTABLE_COLS - 1;
|
||||
}
|
||||
break;
|
||||
case "tab":
|
||||
case "vim_right":
|
||||
case "right_arrow":
|
||||
col_focus += 1;
|
||||
if (col_focus >= MAX_SELECTABLE_COLS) {
|
||||
col_focus = 0;
|
||||
}
|
||||
break;
|
||||
case "vim_down":
|
||||
case "down_arrow":
|
||||
row_focus += 1;
|
||||
break;
|
||||
case "vim_up":
|
||||
case "up_arrow":
|
||||
row_focus -= 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue