mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 02:17:19 +00:00
recent_topics: Extract arrow key navigation into seperate functions.
This is preperatory commit for #21654. We extract the logic for arrow key navigation when focused on table to separate functions so it is easy to add more functionality in future and will not clutter the switch block. Fixes a part of: #21654
This commit is contained in:
@@ -720,6 +720,30 @@ export function focus_clicked_element(topic_row_index, col, topic_key) {
|
||||
set_table_focus(row_focus, col_focus);
|
||||
}
|
||||
|
||||
function left_arrow_navigation() {
|
||||
col_focus -= 1;
|
||||
|
||||
if (col_focus < 0) {
|
||||
col_focus = MAX_SELECTABLE_COLS - 1;
|
||||
}
|
||||
}
|
||||
|
||||
function right_arrow_navigation() {
|
||||
col_focus += 1;
|
||||
|
||||
if (col_focus >= MAX_SELECTABLE_COLS) {
|
||||
col_focus = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function up_arrow_navigation() {
|
||||
row_focus -= 1;
|
||||
}
|
||||
|
||||
function down_arrow_navigation() {
|
||||
row_focus += 1;
|
||||
}
|
||||
|
||||
export function change_focused_element($elt, input_key) {
|
||||
// Called from hotkeys.js; like all logic in that module,
|
||||
// returning true will cause the caller to do
|
||||
@@ -833,18 +857,12 @@ export function change_focused_element($elt, input_key) {
|
||||
case "shift_tab":
|
||||
case "vim_left":
|
||||
case "left_arrow":
|
||||
col_focus -= 1;
|
||||
if (col_focus < 0) {
|
||||
col_focus = MAX_SELECTABLE_COLS - 1;
|
||||
}
|
||||
left_arrow_navigation();
|
||||
break;
|
||||
case "tab":
|
||||
case "vim_right":
|
||||
case "right_arrow":
|
||||
col_focus += 1;
|
||||
if (col_focus >= MAX_SELECTABLE_COLS) {
|
||||
col_focus = 0;
|
||||
}
|
||||
right_arrow_navigation();
|
||||
break;
|
||||
case "vim_down":
|
||||
// We stop user at last table row
|
||||
@@ -857,10 +875,10 @@ export function change_focused_element($elt, input_key) {
|
||||
if (is_focus_at_last_table_row()) {
|
||||
return true;
|
||||
}
|
||||
row_focus += 1;
|
||||
down_arrow_navigation();
|
||||
break;
|
||||
case "down_arrow":
|
||||
row_focus += 1;
|
||||
down_arrow_navigation();
|
||||
break;
|
||||
case "vim_up":
|
||||
// See comment on vim_down.
|
||||
@@ -870,10 +888,10 @@ export function change_focused_element($elt, input_key) {
|
||||
if (row_focus === 0) {
|
||||
return true;
|
||||
}
|
||||
row_focus -= 1;
|
||||
up_arrow_navigation();
|
||||
break;
|
||||
case "up_arrow":
|
||||
row_focus -= 1;
|
||||
up_arrow_navigation();
|
||||
}
|
||||
set_table_focus(row_focus, col_focus, true);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user