From 709fbe5c0a68dd4acbfef7da4ea08732cd237b8e Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Tue, 9 Mar 2021 12:21:32 +0000 Subject: [PATCH] recent_topics: Return false when escape is unhandled. When user presses escape but there is no action that recent topics can perform on it, it returns false. The final state of focus is the focus on topics table. If the focus is on table and not on RT search or filters, we return false to indicate that the key was unhandled by recent topics. This will allow escape to take user to another view if recent topics is not the default view. --- static/js/hotkey.js | 7 ++++++- static/js/recent_topics.js | 14 +++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/static/js/hotkey.js b/static/js/hotkey.js index bd866cee9c..dd3d0c24cc 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -214,6 +214,12 @@ export function in_content_editable_widget(e) { // Returns true if we handled it, false if the browser should. export function process_escape_key(e) { + if (hashchange.in_recent_topics_hash() && recent_topics.change_focused_element(e, "escape")) { + // Recent topics uses escape to make focus from RT search / filters to topics table. + // If focus already in table it returns false. + return true; + } + if (in_content_editable_widget(e)) { return false; } @@ -504,7 +510,6 @@ export function process_hotkey(e, hotkey) { case "tab": case "shift_tab": case "open_recent_topics": - case "escape": if ( hashchange.in_recent_topics_hash() && !popovers.any_active() && diff --git a/static/js/recent_topics.js b/static/js/recent_topics.js index 103d08d798..a29c4ca6d9 100644 --- a/static/js/recent_topics.js +++ b/static/js/recent_topics.js @@ -600,6 +600,9 @@ export function change_focused_element(e, input_key) { current_focus_elem = $("#recent_topics_search"); return true; case "escape": + if (current_focus_elem === "table") { + return false; + } set_table_focus(row_focus, col_focus); return true; } @@ -627,12 +630,20 @@ export function change_focused_element(e, input_key) { case "down_arrow": set_table_focus(row_focus, col_focus); return true; + case "escape": + if (current_focus_elem === "table") { + return false; + } + set_table_focus(row_focus, col_focus); + return true; } } else if (current_focus_elem === "table") { // For arrowing around the table of topics, we implement left/right // wraparound. Going off the top or the bottom takes one // to the navigation at the top (see set_table_focus). switch (input_key) { + case "escape": + return false; case "open_recent_topics": set_default_focus(); return true; @@ -663,8 +674,9 @@ export function change_focused_element(e, input_key) { set_table_focus(row_focus, col_focus); return true; } - if (current_focus_elem) { + if (current_focus_elem && input_key !== "escape") { current_focus_elem.trigger("focus"); + return true; } return false;