From e2a21303ebdc843e7fdb5a51d0ab81a9727e382b Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 4 Apr 2017 12:04:59 -0700 Subject: [PATCH] hotkeys: Simplify up/down handling for stream settings. We've had this kind of hacky setting called message_view_only for a long time in the hotkeys code, and it originally helped optimize the code a bit. It wasn't well maintained, and people started adding non-message-view behavior to the arrow keys without flipping that flag to false. This change finally flips the flag to false, which simplifies some of our logic. --- frontend_tests/node_tests/hotkey.js | 3 +-- static/js/hotkey.js | 13 +++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js index e55476bcde..46b4a58c03 100644 --- a/frontend_tests/node_tests/hotkey.js +++ b/frontend_tests/node_tests/hotkey.js @@ -307,16 +307,15 @@ function stubbing(func_name_to_stub, test_function) { assert_mapping('up_arrow', 'navigate.up'); hotkey.is_subs = return_true; - global.ui_state.home_tab_obscured = return_true; assert_mapping('up_arrow', 'subs.switch_rows'); assert_mapping('down_arrow', 'subs.switch_rows'); - global.ui_state.home_tab_obscured = return_false; hotkey.is_lightbox_open = return_true; assert_mapping('left_arrow', 'lightbox.prev'); assert_mapping('right_arrow', 'lightbox.next'); hotkey.is_editing_stream_name = return_true; + hotkey.is_subs = return_false; assert_unmapped('down_arrow'); assert_unmapped('up_arrow'); diff --git a/static/js/hotkey.js b/static/js/hotkey.js index 98c14935a8..cbea82357b 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -66,8 +66,8 @@ var keydown_unshift_mappings = { 36: {name: 'home', message_view_only: true}, // home 37: {name: 'left_arrow', message_view_only: false}, // left arrow 39: {name: 'right_arrow', message_view_only: false}, // right arrow - 38: {name: 'up_arrow', message_view_only: true}, // up arrow - 40: {name: 'down_arrow', message_view_only: true}, // down arrow + 38: {name: 'up_arrow', message_view_only: false}, // up arrow + 40: {name: 'down_arrow', message_view_only: false}, // down arrow }; var keydown_ctrl_mappings = { @@ -457,13 +457,14 @@ exports.process_hotkey = function (e, hotkey) { } if (hotkey.message_view_only && ui_state.home_tab_obscured()) { - if ((event_name === 'up_arrow' || event_name === 'down_arrow') && exports.is_subs()) { - subs.switch_rows(event_name); - return true; - } return false; } + if ((event_name === 'up_arrow' || event_name === 'down_arrow') && exports.is_subs()) { + subs.switch_rows(event_name); + return true; + } + if (exports.is_editing_stream_name(e)) { // We handle the enter key in process_enter_key(). // We ignore all other keys.