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:
Tim Abbott
2018-04-13 16:10:22 -07:00
parent dbbd3627b5
commit 5ae9505fdc
5 changed files with 10 additions and 10 deletions

View File

@@ -485,7 +485,7 @@ MessageListView.prototype = {
function restore_scroll_position() {
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();
}
}
@@ -815,6 +815,11 @@ MessageListView.prototype = {
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) {
// target_offset is the target number of pixels between the top of the
// viewable window and the selected message
@@ -831,7 +836,7 @@ MessageListView.prototype = {
this.list.select_id(this.list.selected_id(), {use_closest: true});
}
message_viewport.set_message_offset(target_offset);
this.set_message_offset(target_offset);
}
},