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.
This commit is contained in:
Steve Howell 2017-04-04 12:04:59 -07:00 committed by Tim Abbott
parent 4a3211d6af
commit e2a21303eb
2 changed files with 8 additions and 8 deletions

View File

@ -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');

View File

@ -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.