mirror of https://github.com/zulip/zulip.git
Make select_message and friends take an options argument
The select_and_show_by_id function is now subsumed by select_message_by_id. (imported from commit 3dbe9cf9d253b64733f269b6dc78c144100927ca)
This commit is contained in:
parent
35bb3613cd
commit
bb64eb717f
|
@ -40,7 +40,7 @@ var globals =
|
|||
+ ' keep_pointer_in_view move_pointer_at_page_top_and_bottom'
|
||||
+ ' respond_to_message'
|
||||
+ ' select_message select_message_by_id'
|
||||
+ ' scroll_to_selected select_and_show_by_id'
|
||||
+ ' scroll_to_selected'
|
||||
+ ' selected_message selected_message_id'
|
||||
+ ' start_reload_app reloading_app do_reload_app_preserving_compose'
|
||||
+ ' at_top_of_viewport at_bottom_of_viewport'
|
||||
|
|
|
@ -45,7 +45,7 @@ function process_hotkey(code) {
|
|||
if (directional_hotkeys.hasOwnProperty(code)) {
|
||||
next_message = directional_hotkeys[code](selected_message);
|
||||
if (next_message.length !== 0) {
|
||||
select_message(next_message, true);
|
||||
select_message(next_message, {then_scroll: true});
|
||||
}
|
||||
if ((next_message.length === 0) && (code === 40 || code === 106)) {
|
||||
// At the last message, scroll to the bottom so we have
|
||||
|
@ -70,13 +70,13 @@ function process_hotkey(code) {
|
|||
switch (code) {
|
||||
case 33: // Page Up
|
||||
if (at_top_of_viewport()) {
|
||||
select_message(rows.first_visible(), false);
|
||||
select_message(rows.first_visible(), {then_scroll: false});
|
||||
}
|
||||
return false; // We want the browser to actually page up and down
|
||||
case 32: // Spacebar
|
||||
case 34: // Page Down
|
||||
if (at_bottom_of_viewport()) {
|
||||
select_message(rows.last_visible(), false);
|
||||
select_message(rows.last_visible(), {then_scroll: false});
|
||||
}
|
||||
return false;
|
||||
case 27: // Esc: cancel compose or un-narrow
|
||||
|
|
|
@ -45,9 +45,9 @@ function do_narrow(description, filter_function) {
|
|||
|
||||
// Indicate both which message is persistently selected and which
|
||||
// is temporarily selected
|
||||
select_and_show_by_id(selected_message_id);
|
||||
select_message_by_id(selected_message_id, {then_scroll: false});
|
||||
selected_message_class = "narrowed_selected_message";
|
||||
select_and_show_by_id(target_id);
|
||||
select_message_by_id(target_id, {then_scroll: true});
|
||||
scroll_to_selected();
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ exports.show_all_messages = function () {
|
|||
|
||||
selected_message_class = "selected_message";
|
||||
// Includes scrolling.
|
||||
select_and_show_by_id(persistent_message_id);
|
||||
select_message_by_id(persistent_message_id, {then_scroll: true});
|
||||
|
||||
scroll_to_selected();
|
||||
};
|
||||
|
|
|
@ -190,18 +190,12 @@ function respond_to_message(reply_type) {
|
|||
}
|
||||
|
||||
// Called by mouseover etc.
|
||||
function select_message_by_id(message_id) {
|
||||
if (message_id === selected_message_id) {
|
||||
function select_message_by_id(message_id, opts) {
|
||||
opts = $.extend({}, {then_scroll: false}, opts);
|
||||
if (message_id === selected_message_id && ! opts.then_scroll) {
|
||||
return;
|
||||
}
|
||||
select_message(rows.get(message_id), false);
|
||||
}
|
||||
|
||||
// Called on page load and when we [un]narrow.
|
||||
// Forces a call to select_message even if the id has not changed,
|
||||
// because the visible table might have.
|
||||
function select_and_show_by_id(message_id) {
|
||||
select_message(rows.get(message_id), true);
|
||||
select_message(rows.get(message_id), opts);
|
||||
}
|
||||
|
||||
var last_message_id_sent = -1;
|
||||
|
@ -234,7 +228,8 @@ function update_selected_message(message) {
|
|||
selected_message = message;
|
||||
}
|
||||
|
||||
function select_message(next_message, scroll_to) {
|
||||
function select_message(next_message, opts) {
|
||||
opts = $.extend({}, {then_scroll: false}, opts);
|
||||
|
||||
/* If the message exists but is hidden, try to find the next visible one. */
|
||||
if (next_message.length !== 0 && next_message.is(':hidden')) {
|
||||
|
@ -252,7 +247,7 @@ function select_message(next_message, scroll_to) {
|
|||
|
||||
update_selected_message(next_message);
|
||||
|
||||
if (scroll_to) {
|
||||
if (opts.then_scroll) {
|
||||
recenter_view(next_message);
|
||||
}
|
||||
}
|
||||
|
@ -523,7 +518,7 @@ function add_messages(data) {
|
|||
// If we received the initially selected message, select it on the client side,
|
||||
// but not if the user has already selected another one during load.
|
||||
if ((selected_message_id === -1) && (message_dict.hasOwnProperty(initial_pointer))) {
|
||||
select_and_show_by_id(initial_pointer);
|
||||
select_message_by_id(initial_pointer, {then_scroll: true});
|
||||
}
|
||||
|
||||
// If we prepended messages, then we need to scroll back to the pointer.
|
||||
|
@ -534,7 +529,7 @@ function add_messages(data) {
|
|||
// We also need to re-select the message by ID, because we might have
|
||||
// removed and re-added the row as part of prepend collapsing.
|
||||
if ((data.where === 'top') && (selected_message_id >= 0)) {
|
||||
select_and_show_by_id(selected_message_id);
|
||||
select_message_by_id(selected_message_id, {then_scroll: true});
|
||||
}
|
||||
|
||||
if (autocomplete_needs_update)
|
||||
|
|
Loading…
Reference in New Issue