Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

recent_topics: Extract arrow key navigation into seperate functions.

madrix01c5fed915cfd2
diff --git a/static/js/recent_topics_ui.js b/static/js/recent_topics_ui.js
index bb2a26348b0..dafb598c0a4 100644
--- a/static/js/recent_topics_ui.js
+++ b/static/js/recent_topics_ui.js
@@ -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;