message_list: Move and deduplicate reselect_selected_id functions.

redo_selection and reselect_selected_id did the same thing: Reselect
the currently selected message as a result of internal rendering. I
combine the useful features of both -- not crashing if no message is
selected (id -1) and passing the `from_rendering` option, to avoid
potentially triggering an additional rerender.
This commit is contained in:
Tim Abbott 2022-09-22 17:09:42 -07:00
parent eba390c6b2
commit 1b18f1fb5d
1 changed files with 9 additions and 13 deletions

View File

@ -203,10 +203,6 @@ export class MessageList {
$(document).trigger(new $.Event("message_selected.zulip", opts)); $(document).trigger(new $.Event("message_selected.zulip", opts));
} }
reselect_selected_id() {
this.select_id(this.data.selected_id(), {from_rendering: true});
}
selected_message() { selected_message() {
return this.get(this.data.selected_id()); return this.get(this.data.selected_id());
} }
@ -326,9 +322,17 @@ export class MessageList {
$row.removeClass("unread"); $row.removeClass("unread");
} }
reselect_selected_id() {
const selected_id = this.data.selected_id();
if (selected_id !== -1) {
this.select_id(this.data.selected_id(), {from_rendering: true});
}
}
rerender_view() { rerender_view() {
this.view.rerender_preserving_scrolltop(); this.view.rerender_preserving_scrolltop();
this.redo_selection(); this.reselect_selected_id();
} }
rerender() { rerender() {
@ -349,14 +353,6 @@ export class MessageList {
this.rerender_view(); this.rerender_view();
} }
redo_selection() {
const selected_id = this.data.selected_id();
if (selected_id !== -1) {
this.select_id(selected_id);
}
}
update_muting_and_rerender() { update_muting_and_rerender() {
this.data.update_items_for_muting(); this.data.update_items_for_muting();
// We need to rerender whether or not the narrow hides muted // We need to rerender whether or not the narrow hides muted