From 1b18f1fb5de737d60439b2a097bc5dffc38a13b1 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 22 Sep 2022 17:09:42 -0700 Subject: [PATCH] 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. --- static/js/message_list.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/static/js/message_list.js b/static/js/message_list.js index 7570c1ff00..daedcd4706 100644 --- a/static/js/message_list.js +++ b/static/js/message_list.js @@ -203,10 +203,6 @@ export class MessageList { $(document).trigger(new $.Event("message_selected.zulip", opts)); } - reselect_selected_id() { - this.select_id(this.data.selected_id(), {from_rendering: true}); - } - selected_message() { return this.get(this.data.selected_id()); } @@ -326,9 +322,17 @@ export class MessageList { $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() { this.view.rerender_preserving_scrolltop(); - this.redo_selection(); + this.reselect_selected_id(); } rerender() { @@ -349,14 +353,6 @@ export class MessageList { 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() { this.data.update_items_for_muting(); // We need to rerender whether or not the narrow hides muted