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 () { exports.maybe_scroll_to_selected = function () {
// If we have been previously instructed to re-center to the // If we have made a plan to scroll to the selected message but
// selected message, then do so // deferred doing so, do so here.
if (pointer.recenter_pointer_on_display) { if (scroll_to_selected_planned) {
exports.scroll_to_selected(); 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 // See https://zulip.readthedocs.io/en/latest/subsystems/pointer.html for notes on
// how this system is designed. // 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() { 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

@@ -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 // In case we added messages to what's visible in the home
// make sure the pointer is still visible. We don't want the auto-scroll handler to move // view, we need to re-scroll to make sure the pointer is
// our pointer to the old scroll location before we have a chance to update it. // still visible. We don't want the auto-scroll handler to
pointer.set_recenter_pointer_on_display(true); // 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(); message_scroll.suppress_selection_update_on_next_scroll();
if (!home_msg_list.empty()) { if (!home_msg_list.empty()) {