message_list: Extract rerender_with_target_scrolltop.

We may find this useful in upcoming edits to the muting code.
This commit is contained in:
Tim Abbott 2018-04-13 15:47:02 -07:00
parent 0c219a1905
commit a8d237b252
1 changed files with 9 additions and 3 deletions

View File

@ -812,20 +812,26 @@ MessageListView.prototype = {
if (selected_in_view) { if (selected_in_view) {
old_offset = selected_row.offset().top; old_offset = selected_row.offset().top;
} }
return this.rerender_with_target_scrolltop(selected_row, old_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
this.clear_table(); this.clear_table();
this.render(this.list.all_messages().slice(this._render_win_start, this._render_win_end), 'bottom'); this.render(this.list.all_messages().slice(this._render_win_start,
this._render_win_end), 'bottom');
// If we could see the newly selected message, scroll the // If we could see the newly selected message, scroll the
// window such that the newly selected message is at the // window such that the newly selected message is at the
// same location as it would have been before we // same location as it would have been before we
// re-rendered. // re-rendered.
if (selected_in_view) { if (target_offset !== undefined) {
if (this.selected_row().length === 0 && this.list.selected_id() > -1) { if (this.selected_row().length === 0 && this.list.selected_id() > -1) {
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(old_offset); message_viewport.set_message_offset(target_offset);
} }
}, },