mirror of https://github.com/zulip/zulip.git
Speed up key handling by adding modals.is_active().
The function modals.is_active() can see if modals are open without having to look at the DOM. This should make it snappier to type in the compose box. Even if the speedup is pretty minor, not having to worry about jQuery slowness should make it easier to diagnose future compose box issues. The new function gets used in other places, too, where performance isn't so much an issue.
This commit is contained in:
parent
3c0ef6295f
commit
742c55f514
|
@ -177,11 +177,11 @@ function stubbing(func_name_to_stub, test_function) {
|
|||
}
|
||||
|
||||
_.each([return_true, return_false], function (is_settings_page) {
|
||||
_.each([return_true, return_false], function (home_tab_obscured) {
|
||||
_.each([return_true, return_false], function (is_active) {
|
||||
_.each([return_true, return_false], function (is_info_overlay) {
|
||||
hotkey.is_settings_page = is_settings_page;
|
||||
set_global('ui_state', {home_tab_obscured: home_tab_obscured,
|
||||
is_info_overlay: is_info_overlay});
|
||||
set_global('modals', {is_active: is_active});
|
||||
set_global('ui_state', {is_info_overlay: is_info_overlay});
|
||||
|
||||
test_normal_typing();
|
||||
});
|
||||
|
|
|
@ -314,7 +314,7 @@ $(function () {
|
|||
});
|
||||
|
||||
$(".brand").on('click', function (e) {
|
||||
if (ui_state.home_tab_obscured()) {
|
||||
if (modals.is_active()) {
|
||||
ui_util.change_tab_to('#home');
|
||||
} else {
|
||||
narrow.restore_home_state();
|
||||
|
|
|
@ -456,7 +456,7 @@ exports.process_hotkey = function (e, hotkey) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (hotkey.message_view_only && ui_state.home_tab_obscured()) {
|
||||
if (hotkey.message_view_only && modals.is_active()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,10 @@ function reset_state() {
|
|||
open_modal_name = undefined;
|
||||
}
|
||||
|
||||
exports.is_active = function () {
|
||||
return !!open_modal_name;
|
||||
};
|
||||
|
||||
exports.open_overlay = function (opts) {
|
||||
if (!opts.name || !opts.overlay || !opts.on_close) {
|
||||
blueslip.error('Programming error in open_modal');
|
||||
|
|
|
@ -461,7 +461,7 @@ exports.restore_home_state = function () {
|
|||
// If we click on the Home link from another nav pane, just go
|
||||
// back to the state you were in (possibly still narrowed) before
|
||||
// you left the Home pane.
|
||||
if (!ui_state.home_tab_obscured()) {
|
||||
if (!modals.is_active()) {
|
||||
exports.deactivate();
|
||||
}
|
||||
navigate.maybe_scroll_to_selected();
|
||||
|
|
|
@ -427,7 +427,7 @@ $(function () {
|
|||
if (e.metaKey || e.ctrlKey) {
|
||||
return;
|
||||
}
|
||||
if (ui_state.home_tab_obscured()) {
|
||||
if (modals.is_active()) {
|
||||
ui_util.change_tab_to('#home');
|
||||
}
|
||||
var stream = $(e.target).parents('li').attr('data-name');
|
||||
|
@ -500,7 +500,7 @@ function maybe_select_stream(e) {
|
|||
var topStream = $('#stream_filters li.narrow-filter').first().data('name');
|
||||
if (topStream !== undefined) {
|
||||
// undefined if there are no results
|
||||
if (ui_state.home_tab_obscured()) {
|
||||
if (modals.is_active()) {
|
||||
ui_util.change_tab_to('#home');
|
||||
}
|
||||
exports.clear_and_hide_search();
|
||||
|
|
|
@ -11,7 +11,7 @@ exports.update_in_home_view = function (sub, value) {
|
|||
var msg_offset;
|
||||
var saved_ypos;
|
||||
// Save our current scroll position
|
||||
if (ui_state.home_tab_obscured()) {
|
||||
if (modals.is_active()) {
|
||||
saved_ypos = message_viewport.scrollTop();
|
||||
} else if (home_msg_list === current_msg_list &&
|
||||
current_msg_list.selected_row().offset() !== null) {
|
||||
|
@ -24,7 +24,7 @@ exports.update_in_home_view = function (sub, value) {
|
|||
message_util.add_messages(message_list.all.all_messages(), home_msg_list);
|
||||
|
||||
// Ensure we're still at the same scroll position
|
||||
if (ui_state.home_tab_obscured()) {
|
||||
if (modals.is_active()) {
|
||||
message_viewport.scrollTop(saved_ypos);
|
||||
} else if (home_msg_list === current_msg_list) {
|
||||
// We pass use_closest to handle the case where the
|
||||
|
|
|
@ -212,7 +212,7 @@ exports.set_click_handlers = function (callbacks) {
|
|||
|
||||
// In a more componentized world, we would delegate some
|
||||
// of this stuff back up to our parents.
|
||||
if (ui_state.home_tab_obscured()) {
|
||||
if (modals.is_active()) {
|
||||
ui_util.change_tab_to('#home');
|
||||
}
|
||||
|
||||
|
|
|
@ -504,7 +504,7 @@ function welcome() {
|
|||
}
|
||||
|
||||
exports.start = function () {
|
||||
if (ui_state.home_tab_obscured()) {
|
||||
if (modals.is_active()) {
|
||||
ui_util.change_tab_to('#home');
|
||||
}
|
||||
narrow.deactivate();
|
||||
|
|
|
@ -68,7 +68,7 @@ $(function () {
|
|||
});
|
||||
|
||||
message_viewport.message_pane.mousewheel(function (e, delta) {
|
||||
if (!ui_state.home_tab_obscured()) {
|
||||
if (!modals.is_active()) {
|
||||
// In the message view, we use a throttled mousewheel handler.
|
||||
throttled_mousewheelhandler(e, delta);
|
||||
}
|
||||
|
|
|
@ -2,14 +2,6 @@ var ui_state = (function () {
|
|||
|
||||
var exports = {};
|
||||
|
||||
exports.home_tab_obscured = function () {
|
||||
if ($('.overlay.show').length > 0) {
|
||||
return 'modal';
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.is_info_overlay = function () {
|
||||
return ($(".informational-overlays").hasClass("show"));
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue