pointer: Move scroll suppression to message_scroll.js.

This is clearly a better home for it, since message_scroll.js is the
only place that reads it, and also lets us provide a clearer name for
the functionality.
This commit is contained in:
Tim Abbott
2020-06-17 23:29:08 -07:00
committed by Tim Abbott
parent 94e6cb9abd
commit 052dbb0716
4 changed files with 14 additions and 13 deletions

View File

@@ -1,5 +1,13 @@
let actively_scrolling = false; 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_older_messages_indicator_showing = false;
let loading_newer_messages_indicator_showing = false; let loading_newer_messages_indicator_showing = false;
exports.show_loading_older = function () { exports.show_loading_older = function () {
@@ -111,10 +119,10 @@ exports.scroll_finished = function () {
return; return;
} }
if (!pointer.suppress_scroll_pointer_update) { if (update_selection_on_next_scroll) {
message_viewport.keep_pointer_in_view(); message_viewport.keep_pointer_in_view();
} else { } else {
pointer.set_suppress_scroll_pointer_update(false); update_selection_on_next_scroll = true;
} }
floating_recipient_bar.update(); floating_recipient_bar.update();

View File

@@ -123,7 +123,7 @@ exports.set_message_position = function (message_top, message_height, viewport_i
message_top message_top
- message_offset; - 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); exports.scrollTop(new_scroll_top);
}; };
@@ -280,7 +280,7 @@ exports.is_narrow = function () {
}; };
exports.system_initiated_animate_scroll = function (scroll_amount) { 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(); const viewport_offset = exports.scrollTop();
in_stoppable_autoscroll = true; in_stoppable_autoscroll = true;
exports.message_pane.animate({ exports.message_pane.animate({
@@ -292,7 +292,7 @@ exports.system_initiated_animate_scroll = function (scroll_amount) {
}; };
exports.user_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 in_stoppable_autoscroll = false; // defensive
const viewport_offset = exports.scrollTop(); const viewport_offset = exports.scrollTop();

View File

@@ -6,13 +6,6 @@ exports.set_recenter_pointer_on_display = function (value) {
exports.recenter_pointer_on_display = 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() { exports.initialize = function initialize() {
$(document).on('message_selected.zulip', function (event) { $(document).on('message_selected.zulip', function (event) {
if (event.id === -1) { if (event.id === -1) {

View File

@@ -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 // 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. // our pointer to the old scroll location before we have a chance to update it.
pointer.set_recenter_pointer_on_display(true); 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()) { if (!home_msg_list.empty()) {
message_util.do_unread_count_updates(home_msg_list.all_messages()); message_util.do_unread_count_updates(home_msg_list.all_messages());