mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
message_list: Move set_message_offset into message_list_view.
The refactor in 12509515ae had a subtle
bug, which is that we switched from accessing the message list "this"
(aka the message list being rerendered) to current_msg_list. This
meant that when the narrowed_msg_list was in view and code needed to
modify home_msg_list, we accessed the wrong `selected_row` to preserve
the scroll position of (namely, the one in current_msg_list, not the
one in home_msg_list).
Fix this, by moving the function to be a property of the
message_list_view object, which makes more sense structurally, anyway.
We may, in the future, want to do a similar migration for more of
message_viewport.js.
Fixes #8854.
This commit is contained in:
@@ -485,7 +485,7 @@ MessageListView.prototype = {
|
|||||||
|
|
||||||
function restore_scroll_position() {
|
function restore_scroll_position() {
|
||||||
if (list === current_msg_list && orig_scrolltop_offset !== undefined) {
|
if (list === current_msg_list && orig_scrolltop_offset !== undefined) {
|
||||||
message_viewport.set_message_offset(orig_scrolltop_offset);
|
list.view.set_message_offset(orig_scrolltop_offset);
|
||||||
list.reselect_selected_id();
|
list.reselect_selected_id();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -815,6 +815,11 @@ MessageListView.prototype = {
|
|||||||
return this.rerender_with_target_scrolltop(selected_row, old_offset);
|
return this.rerender_with_target_scrolltop(selected_row, old_offset);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
set_message_offset: function (offset) {
|
||||||
|
var msg = this.selected_row();
|
||||||
|
message_viewport.scrollTop(message_viewport.scrollTop() + msg.offset().top - offset);
|
||||||
|
},
|
||||||
|
|
||||||
rerender_with_target_scrolltop: function (selected_row, target_offset) {
|
rerender_with_target_scrolltop: function (selected_row, target_offset) {
|
||||||
// target_offset is the target number of pixels between the top of the
|
// target_offset is the target number of pixels between the top of the
|
||||||
// viewable window and the selected message
|
// viewable window and the selected message
|
||||||
@@ -831,7 +836,7 @@ MessageListView.prototype = {
|
|||||||
this.list.select_id(this.list.selected_id(), {use_closest: true});
|
this.list.select_id(this.list.selected_id(), {use_closest: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
message_viewport.set_message_offset(target_offset);
|
this.set_message_offset(target_offset);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -223,11 +223,6 @@ exports.scrollTop = function viewport_scrollTop(target_scrollTop) {
|
|||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.set_message_offset = function viewport_set_message_offset(offset) {
|
|
||||||
var msg = current_msg_list.selected_row();
|
|
||||||
exports.scrollTop(exports.scrollTop() + msg.offset().top - offset);
|
|
||||||
};
|
|
||||||
|
|
||||||
function make_dimen_wrapper(dimen_name, dimen_func) {
|
function make_dimen_wrapper(dimen_name, dimen_func) {
|
||||||
dimensions[dimen_name] = new util.CachedValue({
|
dimensions[dimen_name] = new util.CachedValue({
|
||||||
compute_value: function () {
|
compute_value: function () {
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ exports.activate = function (raw_operators, opts) {
|
|||||||
// Scroll so that the selected message is in the same
|
// Scroll so that the selected message is in the same
|
||||||
// position in the viewport as it was prior to
|
// position in the viewport as it was prior to
|
||||||
// narrowing
|
// narrowing
|
||||||
message_viewport.set_message_offset(then_select_offset);
|
message_list.narrowed.view.set_message_offset(then_select_offset);
|
||||||
}
|
}
|
||||||
unread_ops.process_visible();
|
unread_ops.process_visible();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ exports.update_in_home_view = function (sub, value) {
|
|||||||
home_msg_list.select_id(home_msg_list.selected_id(),
|
home_msg_list.select_id(home_msg_list.selected_id(),
|
||||||
{use_closest: true, empty_ok: true});
|
{use_closest: true, empty_ok: true});
|
||||||
if (current_msg_list.selected_id() !== -1) {
|
if (current_msg_list.selected_id() !== -1) {
|
||||||
message_viewport.set_message_offset(msg_offset);
|
current_msg_list.view.set_message_offset(msg_offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ $(function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (event.target_scroll_offset !== undefined) {
|
if (event.target_scroll_offset !== undefined) {
|
||||||
message_viewport.set_message_offset(event.target_scroll_offset);
|
current_msg_list.view.set_message_offset(event.target_scroll_offset);
|
||||||
} else {
|
} else {
|
||||||
// Scroll to place the message within the current view;
|
// Scroll to place the message within the current view;
|
||||||
// but if this is the initial placement of the pointer,
|
// but if this is the initial placement of the pointer,
|
||||||
|
|||||||
Reference in New Issue
Block a user