mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
hotkeys: Handle up/down arrows in settings page.
The up/down arrows now navigate the left pane of the settings menu. The code here was originally implemented as part of our settings redesign, but the code was added in a place that became unreachable after we fixed a bug with home_tab_obscured(). This commit resurrects the code and places the guts of it in settings.js. It is possible that we want to clean this code up eventually to deal better with hidden blocks.
This commit is contained in:
@@ -317,6 +317,10 @@ function stubbing(func_name_to_stub, test_function) {
|
||||
assert_mapping('left_arrow', 'lightbox.prev');
|
||||
assert_mapping('right_arrow', 'lightbox.next');
|
||||
|
||||
hotkey.is_editing_stream_name = return_true;
|
||||
assert_unmapped('down_arrow');
|
||||
assert_unmapped('up_arrow');
|
||||
|
||||
hotkey.is_settings_page = return_true;
|
||||
assert_unmapped('end');
|
||||
assert_unmapped('home');
|
||||
@@ -325,7 +329,6 @@ function stubbing(func_name_to_stub, test_function) {
|
||||
assert_unmapped('page_down');
|
||||
assert_unmapped('spacebar');
|
||||
|
||||
hotkey.is_editing_stream_name = return_true;
|
||||
assert_unmapped('down_arrow');
|
||||
assert_unmapped('up_arrow');
|
||||
assert_mapping('up_arrow', 'settings.handle_up_arrow');
|
||||
assert_mapping('down_arrow', 'settings.handle_down_arrow');
|
||||
}());
|
||||
|
||||
@@ -436,6 +436,18 @@ exports.process_hotkey = function (e, hotkey) {
|
||||
drafts.drafts_handle_events(e, event_name);
|
||||
}
|
||||
|
||||
if (exports.is_settings_page()) {
|
||||
switch (event_name) {
|
||||
case 'up_arrow':
|
||||
settings.handle_up_arrow(e);
|
||||
return true;
|
||||
case 'down_arrow':
|
||||
settings.handle_down_arrow(e);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -479,25 +491,6 @@ exports.process_hotkey = function (e, hotkey) {
|
||||
}
|
||||
}
|
||||
|
||||
if (exports.is_settings_page()) {
|
||||
if (event_name === 'up_arrow') {
|
||||
var prev = e.target.previousElementSibling;
|
||||
|
||||
if ($(prev).css("display") !== "none") {
|
||||
$(prev).focus().click();
|
||||
}
|
||||
return true;
|
||||
} else if (event_name === 'down_arrow') {
|
||||
var next = e.target.nextElementSibling;
|
||||
|
||||
if ($(next).css("display") !== "none") {
|
||||
$(next).focus().click();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Process hotkeys specially when in an input, select, textarea, or send button
|
||||
if (exports.processing_text()) {
|
||||
// Note that there is special handling for enter/escape too, but
|
||||
|
||||
@@ -1040,6 +1040,22 @@ exports.launch_page = function (tab) {
|
||||
$active_tab.click();
|
||||
};
|
||||
|
||||
exports.handle_up_arrow = function (e) {
|
||||
var prev = e.target.previousElementSibling;
|
||||
|
||||
if ($(prev).css("display") !== "none") {
|
||||
$(prev).focus().click();
|
||||
}
|
||||
};
|
||||
|
||||
exports.handle_down_arrow = function (e) {
|
||||
var next = e.target.nextElementSibling;
|
||||
|
||||
if ($(next).css("display") !== "none") {
|
||||
$(next).focus().click();
|
||||
}
|
||||
};
|
||||
|
||||
return exports;
|
||||
}());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user