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.
This commit is contained in:
Aman Agrawal 2021-03-12 07:08:48 +00:00 committed by Steve Howell
parent 06c07109e4
commit d8af33d24e
1 changed files with 26 additions and 0 deletions

View File

@ -545,6 +545,11 @@ export function hide() {
navigate.plan_scroll_to_selected(); 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) { export function change_focused_element(e, input_key) {
// Called from hotkeys.js; like all logic in that module, // Called from hotkeys.js; like all logic in that module,
// returning true will cause the caller to do // returning true will cause the caller to do
@ -669,10 +674,31 @@ export function change_focused_element(e, input_key) {
} }
break; break;
case "vim_down": 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": case "down_arrow":
row_focus += 1; row_focus += 1;
break; break;
case "vim_up": 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": case "up_arrow":
row_focus -= 1; row_focus -= 1;
} }