From 937c85d27834cb6d9941fccd1ac1ef84f97f8e77 Mon Sep 17 00:00:00 2001 From: Mohit Gupta Date: Fri, 10 Jul 2020 23:55:24 +0530 Subject: [PATCH] popovers: Add keyboard support for starred message popovers in sidebar. This commits add arrow, vim_up/vim_down and enter hotkey support for navigating the popover menu when it is open. --- frontend_tests/node_tests/hotkey.js | 1 + static/js/hotkey.js | 10 ++++++++++ static/js/stream_popover.js | 5 +++++ static/templates/starred_messages_sidebar_actions.hbs | 5 +++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js index b550860b19..b6f92f664e 100644 --- a/frontend_tests/node_tests/hotkey.js +++ b/frontend_tests/node_tests/hotkey.js @@ -214,6 +214,7 @@ run_test("basic_chars", () => { stream_popped: return_false, topic_popped: return_false, all_messages_popped: return_false, + starred_messages_popped: return_false, }); set_global("emoji_picker", { reactions_popped: return_false, diff --git a/static/js/hotkey.js b/static/js/hotkey.js index 656329c638..ea6f7d669d 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -316,6 +316,11 @@ exports.process_enter_key = function (e) { return true; } + if (stream_popover.starred_messages_popped()) { + stream_popover.starred_messages_sidebar_menu_handle_keyboard("enter"); + return true; + } + if (overlays.settings_open()) { // On the settings page just let the browser handle // the Enter key for things like submitting forms. @@ -583,6 +588,11 @@ exports.process_hotkey = function (e, hotkey) { stream_popover.all_messages_sidebar_menu_handle_keyboard(event_name); return true; } + + if (stream_popover.starred_messages_popped()) { + stream_popover.starred_messages_sidebar_menu_handle_keyboard(event_name); + return true; + } } // The next two sections date back to 00445c84 and are Mac/Chrome-specific, diff --git a/static/js/stream_popover.js b/static/js/stream_popover.js index 04039cdd40..d549499200 100644 --- a/static/js/stream_popover.js +++ b/static/js/stream_popover.js @@ -44,6 +44,11 @@ exports.all_messages_sidebar_menu_handle_keyboard = (key) => { popovers.popover_items_handle_keyboard(key, items); }; +exports.starred_messages_sidebar_menu_handle_keyboard = (key) => { + const items = get_popover_menu_items(starred_messages_sidebar_elem); + popovers.popover_items_handle_keyboard(key, items); +}; + function elem_to_stream_id(elem) { const stream_id = parseInt(elem.attr("data-stream-id"), 10); diff --git a/static/templates/starred_messages_sidebar_actions.hbs b/static/templates/starred_messages_sidebar_actions.hbs index 9ba9648d09..3b95162a29 100644 --- a/static/templates/starred_messages_sidebar_actions.hbs +++ b/static/templates/starred_messages_sidebar_actions.hbs @@ -1,13 +1,14 @@ {{! Contents of the "starred messages sidebar" popup }}