pointer: Move planned scroll logic to navigate.js.

Like the last commit, this is clearly a better home for this state,
since all reads to the data object are in navigate.js already.
This commit is contained in:
Tim Abbott 2020-06-17 23:35:18 -07:00 committed by Tim Abbott
parent 052dbb0716
commit 5321e8792d
3 changed files with 14 additions and 13 deletions

View File

@ -128,13 +128,17 @@ exports.scroll_to_selected = function () {
}
};
let scroll_to_selected_planned = false;
exports.plan_scroll_to_selected = function () {
scroll_to_selected_planned = true;
};
exports.maybe_scroll_to_selected = function () {
// If we have been previously instructed to re-center to the
// selected message, then do so
if (pointer.recenter_pointer_on_display) {
// If we have made a plan to scroll to the selected message but
// deferred doing so, do so here.
if (scroll_to_selected_planned) {
exports.scroll_to_selected();
pointer.set_recenter_pointer_on_display(false);
scroll_to_selected_planned = false;
}
};

View File

@ -1,11 +1,6 @@
// See https://zulip.readthedocs.io/en/latest/subsystems/pointer.html for notes on
// how this system is designed.
exports.recenter_pointer_on_display = false;
exports.set_recenter_pointer_on_display = function (value) {
exports.recenter_pointer_on_display = value;
};
exports.initialize = function initialize() {
$(document).on('message_selected.zulip', function (event) {
if (event.id === -1) {

View File

@ -31,10 +31,12 @@ exports.update_is_muted = function (sub, value) {
}
}
// In case we added messages to what's visible in the home view, we need to re-scroll to
// 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);
// In case we added messages to what's visible in the home
// view, we need to re-scroll to 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.
navigate.plan_scroll_to_selected();
message_scroll.suppress_selection_update_on_next_scroll();
if (!home_msg_list.empty()) {