From ef906c3cd36a37dcda35bde3c3ffd42cf440a555 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 2 Dec 2013 13:16:37 -0500 Subject: [PATCH] Fix traceback when unnarrowing before home message list has loaded. If we load a browser window in a narrowed view and then un-narrow before the home message list has loaded, we end up attempting to select message ID -1 from home_msg_list even though it is empty, triggering a traceback. (imported from commit eb8b686f6e9c1fa518028e5755ac6196781e92d7) --- static/js/narrow.js | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/static/js/narrow.js b/static/js/narrow.js index e6403f92a5..129d1ff156 100644 --- a/static/js/narrow.js +++ b/static/js/narrow.js @@ -378,29 +378,31 @@ exports.deactivate = function () { message_tour.finish_tour(); current_msg_list = home_msg_list; - var preserve_pre_narrowing_screen_position = - (current_msg_list.selected_row().length > 0) && - (current_msg_list.pre_narrow_offset !== undefined); + if (current_msg_list.selected_id() !== -1) { + var preserve_pre_narrowing_screen_position = + (current_msg_list.selected_row().length > 0) && + (current_msg_list.pre_narrow_offset !== undefined); - if (feature_flags.summarize_read_while_narrowed) { - // TODO: avoid a full re-render - // Necessary to replace messages read in the narrow with summary blocks - current_msg_list.start_summary_exemption(); - current_msg_list.rerender(); - } + if (feature_flags.summarize_read_while_narrowed) { + // TODO: avoid a full re-render + // Necessary to replace messages read in the narrow with summary blocks + current_msg_list.start_summary_exemption(); + current_msg_list.rerender(); + } - // We fall back to the closest selected id, if the user has removed a stream from the home - // view since leaving it the old selected id might no longer be there - current_msg_list.select_id(current_msg_list.selected_id(), { - then_scroll: !preserve_pre_narrowing_screen_position, - use_closest: true - }); + // We fall back to the closest selected id, if the user has removed a stream from the home + // view since leaving it the old selected id might no longer be there + current_msg_list.select_id(current_msg_list.selected_id(), { + then_scroll: !preserve_pre_narrowing_screen_position, + use_closest: true + }); - if (preserve_pre_narrowing_screen_position) { - // We scroll the user back to exactly the offset from the selected - // message that he was at the time that he narrowed. - // TODO: Make this correctly handle the case of resizing while narrowed. - viewport.scrollTop(current_msg_list.selected_row().offset().top - current_msg_list.pre_narrow_offset); + if (preserve_pre_narrowing_screen_position) { + // We scroll the user back to exactly the offset from the selected + // message that he was at the time that he narrowed. + // TODO: Make this correctly handle the case of resizing while narrowed. + viewport.scrollTop(current_msg_list.selected_row().offset().top - current_msg_list.pre_narrow_offset); + } } hashchange.save_narrow();