mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 08:56:10 +00:00
hotkeys: Clean up dispatching of drafts hotkeys.
We now explicitly return true from process_hotkey() when we handle up/down/backspace for the drafts modal. Also, we no longer call preventDefault() from drafts.draft_handle_events(), since the caller does that, and we no longer return `true`, since we were never inspecting the return value anyway.
This commit is contained in:
@@ -15,8 +15,6 @@ set_global('activity', {
|
|||||||
});
|
});
|
||||||
|
|
||||||
set_global('drafts', {
|
set_global('drafts', {
|
||||||
drafts_handle_events: function () { return; },
|
|
||||||
drafts_overlay_open: function () { return; },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
set_global('$', function () {
|
set_global('$', function () {
|
||||||
@@ -281,6 +279,7 @@ function stubbing(func_name_to_stub, test_function) {
|
|||||||
|
|
||||||
list_util.inside_list = return_false;
|
list_util.inside_list = return_false;
|
||||||
global.current_msg_list.empty = return_true;
|
global.current_msg_list.empty = return_true;
|
||||||
|
global.drafts.drafts_overlay_open = return_false;
|
||||||
hotkey.is_settings_page = return_false;
|
hotkey.is_settings_page = return_false;
|
||||||
hotkey.is_subs = return_false;
|
hotkey.is_subs = return_false;
|
||||||
|
|
||||||
@@ -331,4 +330,9 @@ function stubbing(func_name_to_stub, test_function) {
|
|||||||
|
|
||||||
assert_mapping('up_arrow', 'settings.handle_up_arrow');
|
assert_mapping('up_arrow', 'settings.handle_up_arrow');
|
||||||
assert_mapping('down_arrow', 'settings.handle_down_arrow');
|
assert_mapping('down_arrow', 'settings.handle_down_arrow');
|
||||||
|
|
||||||
|
global.drafts.drafts_overlay_open = return_true;
|
||||||
|
assert_mapping('up_arrow', 'drafts.drafts_handle_events');
|
||||||
|
assert_mapping('down_arrow', 'drafts.drafts_handle_events');
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|||||||
@@ -260,10 +260,9 @@ exports.drafts_handle_events = function (e, event_key) {
|
|||||||
// 55 is the minimum distance from the top that will require extra scrolling.
|
// 55 is the minimum distance from the top that will require extra scrolling.
|
||||||
$(".drafts-list")[0].scrollTop = $(".drafts-list")[0].scrollTop - (55 - prev_focus_draft_row.position().top);
|
$(".drafts-list")[0].scrollTop = $(".drafts-list")[0].scrollTop - (55 - prev_focus_draft_row.position().top);
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This detects down arrow key presses when the draft overlay
|
// This detects down arrow key presses when the draft overlay
|
||||||
// is open and scrolls through the drafts.
|
// is open and scrolls through the drafts.
|
||||||
if (event_key === "down_arrow") {
|
if (event_key === "down_arrow") {
|
||||||
@@ -292,10 +291,9 @@ exports.drafts_handle_events = function (e, event_key) {
|
|||||||
$(".drafts-list")[0].scrollTop = $(".drafts-list")[0].scrollTop + 2 - (dist_from_bottom);
|
$(".drafts-list")[0].scrollTop = $(".drafts-list")[0].scrollTop + 2 - (dist_from_bottom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allows user to delete drafts with backspace
|
// Allows user to delete drafts with backspace
|
||||||
if (event_key === "backspace") {
|
if (event_key === "backspace") {
|
||||||
var elt = document.activeElement;
|
var elt = document.activeElement;
|
||||||
@@ -319,8 +317,6 @@ exports.drafts_handle_events = function (e, event_key) {
|
|||||||
if ($("#drafts_table .draft-row").length === 0) {
|
if ($("#drafts_table .draft-row").length === 0) {
|
||||||
$('#drafts_table .no-drafts').show();
|
$('#drafts_table .no-drafts').show();
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -432,8 +432,16 @@ exports.process_hotkey = function (e, hotkey) {
|
|||||||
return exports.process_escape_key(e);
|
return exports.process_escape_key(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (event_name) {
|
||||||
|
// TODO: break out specific handlers for up_arrow,
|
||||||
|
// down_arrow, and backspace
|
||||||
|
case 'up_arrow':
|
||||||
|
case 'down_arrow':
|
||||||
|
case 'backspace':
|
||||||
if (drafts.drafts_overlay_open()) {
|
if (drafts.drafts_overlay_open()) {
|
||||||
drafts.drafts_handle_events(e, event_name);
|
drafts.drafts_handle_events(e, event_name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exports.is_settings_page()) {
|
if (exports.is_settings_page()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user