diff --git a/static/js/message_scroll.js b/static/js/message_scroll.js index 202350177b..77b8c082e5 100644 --- a/static/js/message_scroll.js +++ b/static/js/message_scroll.js @@ -1,5 +1,13 @@ let actively_scrolling = false; +// Tracks whether the next scroll that will complete is initiated by +// code, not the user, and thus should avoid moving the selected +// message. +let update_selection_on_next_scroll = true; +exports.suppress_selection_update_on_next_scroll = function () { + update_selection_on_next_scroll = false; +}; + let loading_older_messages_indicator_showing = false; let loading_newer_messages_indicator_showing = false; exports.show_loading_older = function () { @@ -111,10 +119,10 @@ exports.scroll_finished = function () { return; } - if (!pointer.suppress_scroll_pointer_update) { + if (update_selection_on_next_scroll) { message_viewport.keep_pointer_in_view(); } else { - pointer.set_suppress_scroll_pointer_update(false); + update_selection_on_next_scroll = true; } floating_recipient_bar.update(); diff --git a/static/js/message_viewport.js b/static/js/message_viewport.js index c6ae4a7f19..5e63cea061 100644 --- a/static/js/message_viewport.js +++ b/static/js/message_viewport.js @@ -123,7 +123,7 @@ exports.set_message_position = function (message_top, message_height, viewport_i message_top - message_offset; - pointer.set_suppress_scroll_pointer_update(true); // Gets set to false in the scroll handler. + message_scroll.suppress_selection_update_on_next_scroll(); exports.scrollTop(new_scroll_top); }; @@ -280,7 +280,7 @@ exports.is_narrow = function () { }; exports.system_initiated_animate_scroll = function (scroll_amount) { - pointer.set_suppress_scroll_pointer_update(true); // Gets set to false in the scroll handler. + message_scroll.suppress_selection_update_on_next_scroll(); const viewport_offset = exports.scrollTop(); in_stoppable_autoscroll = true; exports.message_pane.animate({ @@ -292,7 +292,7 @@ exports.system_initiated_animate_scroll = function (scroll_amount) { }; exports.user_initiated_animate_scroll = function (scroll_amount) { - pointer.set_suppress_scroll_pointer_update(true); // Gets set to false in the scroll handler. + message_scroll.suppress_selection_update_on_next_scroll(); in_stoppable_autoscroll = false; // defensive const viewport_offset = exports.scrollTop(); diff --git a/static/js/pointer.js b/static/js/pointer.js index c40be3a688..7e2565f1be 100644 --- a/static/js/pointer.js +++ b/static/js/pointer.js @@ -6,13 +6,6 @@ exports.set_recenter_pointer_on_display = function (value) { exports.recenter_pointer_on_display = value; }; -// Toggles re-centering the pointer in the window -// when All Messages is next clicked by the user -exports.suppress_scroll_pointer_update = false; -exports.set_suppress_scroll_pointer_update = function (value) { - exports.suppress_scroll_pointer_update = value; -}; - exports.initialize = function initialize() { $(document).on('message_selected.zulip', function (event) { if (event.id === -1) { diff --git a/static/js/stream_muting.js b/static/js/stream_muting.js index fc06bb653a..54e1beeb94 100644 --- a/static/js/stream_muting.js +++ b/static/js/stream_muting.js @@ -35,7 +35,7 @@ exports.update_is_muted = function (sub, value) { // make sure the pointer is still visible. We don't want the auto-scroll handler to move // our pointer to the old scroll location before we have a chance to update it. pointer.set_recenter_pointer_on_display(true); - pointer.set_suppress_scroll_pointer_update(true); + message_scroll.suppress_selection_update_on_next_scroll(); if (!home_msg_list.empty()) { message_util.do_unread_count_updates(home_msg_list.all_messages());