mirror of https://github.com/zulip/zulip.git
hotkeys: Ensure navigation hotkeys do not work while overlay is open.
Fixes #7123.
This commit is contained in:
parent
e7de4f5d74
commit
f63585bd6d
|
@ -188,8 +188,8 @@ function stubbing(func_name_to_stub, test_function) {
|
|||
set_global('overlays', {
|
||||
is_active: is_active,
|
||||
settings_open: settings_open,
|
||||
info_overlay_open: info_overlay_open});
|
||||
|
||||
info_overlay_open: info_overlay_open,
|
||||
});
|
||||
test_normal_typing();
|
||||
});
|
||||
});
|
||||
|
@ -198,6 +198,9 @@ function stubbing(func_name_to_stub, test_function) {
|
|||
// Ok, now test keys that work when we're viewing messages.
|
||||
hotkey.processing_text = return_false;
|
||||
overlays.settings_open = return_false;
|
||||
overlays.streams_open = return_false;
|
||||
overlays.lightbox_open = return_false;
|
||||
overlays.drafts_open = return_false;
|
||||
|
||||
page_params.can_create_streams = true;
|
||||
overlays.streams_open = return_true;
|
||||
|
@ -207,8 +210,9 @@ function stubbing(func_name_to_stub, test_function) {
|
|||
assert_mapping('n', 'subs.new_stream_clicked');
|
||||
page_params.can_create_streams = false;
|
||||
assert_unmapped('n');
|
||||
overlays.is_active = return_false;
|
||||
overlays.streams_open = return_false;
|
||||
test_normal_typing();
|
||||
overlays.is_active = return_false;
|
||||
|
||||
assert_mapping('?', 'ui.maybe_show_keyboard_shortcuts');
|
||||
assert_mapping('/', 'search.initiate_search');
|
||||
|
@ -225,10 +229,11 @@ function stubbing(func_name_to_stub, test_function) {
|
|||
|
||||
overlays.is_active = return_true;
|
||||
overlays.drafts_open = return_true;
|
||||
assert_mapping('d', 'drafts.toggle');
|
||||
assert_mapping('d', 'overlays.close_overlay');
|
||||
overlays.drafts_open = return_false;
|
||||
assert_unmapped('d');
|
||||
test_normal_typing();
|
||||
overlays.is_active = return_false;
|
||||
assert_mapping('d', 'drafts.launch');
|
||||
|
||||
// Next, test keys that only work on a selected message.
|
||||
var message_view_only_keys = '@*+RjJkKsSuvi:GM';
|
||||
|
@ -259,10 +264,17 @@ function stubbing(func_name_to_stub, test_function) {
|
|||
assert_mapping('s', 'narrow.by_recipient');
|
||||
assert_mapping('S', 'narrow.by_subject');
|
||||
assert_mapping('u', 'popovers.show_sender_info');
|
||||
assert_mapping('v', 'lightbox.show_from_selected_message');
|
||||
assert_mapping('i', 'popovers.open_message_menu');
|
||||
assert_mapping(':', 'reactions.open_reactions_popover', true);
|
||||
|
||||
overlays.is_active = return_true;
|
||||
overlays.lightbox_open = return_true;
|
||||
assert_mapping('v', 'overlays.close_overlay');
|
||||
overlays.lightbox_open = return_false;
|
||||
test_normal_typing();
|
||||
overlays.is_active = return_false;
|
||||
assert_mapping('v', 'lightbox.show_from_selected_message');
|
||||
|
||||
global.emoji_picker.reactions_popped = return_true;
|
||||
assert_mapping(':', 'emoji_picker.navigate', true);
|
||||
global.emoji_picker.reactions_popped = return_false;
|
||||
|
|
|
@ -555,6 +555,19 @@ exports.process_hotkey = function (e, hotkey) {
|
|||
}
|
||||
}
|
||||
|
||||
// Prevent navigation in the background when the overlays are active.
|
||||
if (overlays.is_active()) {
|
||||
if (event_name === 'view_selected_stream' && overlays.streams_open()) {
|
||||
subs.view_stream();
|
||||
return true;
|
||||
}
|
||||
if (event_name === 'n_key' && overlays.streams_open() && page_params.can_create_streams) {
|
||||
subs.new_stream_clicked();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Shortcuts that don't require a message
|
||||
switch (event_name) {
|
||||
case 'compose': // 'c': compose
|
||||
|
@ -589,26 +602,10 @@ exports.process_hotkey = function (e, hotkey) {
|
|||
case 'stream_cycle_forward':
|
||||
narrow.stream_cycle_forward();
|
||||
return true;
|
||||
case 'view_selected_stream':
|
||||
if (overlays.streams_open()) {
|
||||
subs.view_stream();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 'n_key':
|
||||
if (overlays.streams_open()) {
|
||||
if (page_params.can_create_streams) {
|
||||
subs.new_stream_clicked();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
narrow.narrow_to_next_topic();
|
||||
return true;
|
||||
case 'open_drafts':
|
||||
if (overlays.is_active() && !overlays.drafts_open()) {
|
||||
return false;
|
||||
}
|
||||
drafts.launch();
|
||||
return true;
|
||||
case 'reply_message': // 'r': respond to message
|
||||
|
@ -622,11 +619,6 @@ exports.process_hotkey = function (e, hotkey) {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Prevent navigation in the background when the overlays are active.
|
||||
if (overlays.is_active()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Navigation shortcuts
|
||||
switch (event_name) {
|
||||
case 'down_arrow':
|
||||
|
|
Loading…
Reference in New Issue