From d8af33d24eeacd32a09328ecb693f011f17d2e7a Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Fri, 12 Mar 2021 07:08:48 +0000 Subject: [PATCH] recent_topics: Don't switch focus to input on `k` / `j` keypress. Don't focus on search box when user is at end or start of the table and is using vim keys. This ends up being a bad UX as once user is inside the search box, vim navigation keys cannot be used to take user out of the search box. --- static/js/recent_topics.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/static/js/recent_topics.js b/static/js/recent_topics.js index 695a264377..047694ab9f 100644 --- a/static/js/recent_topics.js +++ b/static/js/recent_topics.js @@ -545,6 +545,11 @@ export function hide() { navigate.plan_scroll_to_selected(); } +function is_focus_at_last_table_row() { + const topic_rows = $("#recent_topics_table table tbody tr"); + return row_focus === topic_rows.length - 1; +} + export function change_focused_element(e, input_key) { // Called from hotkeys.js; like all logic in that module, // returning true will cause the caller to do @@ -669,10 +674,31 @@ export function change_focused_element(e, input_key) { } break; case "vim_down": + // We stop user at last table row + // so that user doesn't end up in + // input box where it is impossible to + // get out of using vim_up / vim_down + // keys. This also blocks the user from + // having `jjjj` typed in the input box + // when continuously pressing `j`. + if (is_focus_at_last_table_row()) { + return true; + } + row_focus += 1; + break; case "down_arrow": row_focus += 1; break; case "vim_up": + // See comment on vim_down. + // Similarly, blocks the user from + // having `kkkk` typed in the input box + // when continuously pressing `k`. + if (row_focus === 0) { + return true; + } + row_focus -= 1; + break; case "up_arrow": row_focus -= 1; }