diff --git a/web/src/compose_actions.js b/web/src/compose_actions.js index 333b514d88..c775ae6dbe 100644 --- a/web/src/compose_actions.js +++ b/web/src/compose_actions.js @@ -90,11 +90,11 @@ function clear_box() { $(".compose_control_button_container:has(.add-poll)").removeClass("disabled-on-hover"); } -export function autosize_message_content() { +export function autosize_message_content(opts) { if (!compose_ui.is_full_size()) { autosize($("textarea#compose-textarea"), { callback() { - maybe_scroll_up_selected_message(); + maybe_scroll_up_selected_message(opts); }, }); } @@ -112,7 +112,7 @@ export function complete_starting_tasks(msg_type, opts) { // by compose.start() for now. Having this as a separate function // makes testing a bit easier. - maybe_scroll_up_selected_message(); + maybe_scroll_up_selected_message(opts); compose_fade.start_compose(msg_type); if (msg_type === "stream") { stream_bar.decorate( @@ -125,7 +125,11 @@ export function complete_starting_tasks(msg_type, opts) { compose_recipient.update_narrow_to_recipient_visibility(); } -export function maybe_scroll_up_selected_message() { +export function maybe_scroll_up_selected_message(opts) { + if (!opts.skip_scrolling_selected_message) { + return; + } + // If the compose box is obscuring the currently selected message, // scroll up until the message is no longer occluded. if (message_lists.current.selected_id() === -1) { @@ -194,7 +198,7 @@ export function start(msg_type, opts) { } popovers.hide_all(); - autosize_message_content(); + autosize_message_content(opts); if (reload_state.is_in_progress()) { return; @@ -456,7 +460,14 @@ export function on_narrow(opts) { return; } } - start("private"); + + // Open the compose box, passing the option to skip attempting + // an animated adjustment to scroll position, which is useless + // because we are called before the narrowing process has set + // the view's scroll position. recenter_view is responsible + // for taking the open compose box into account when placing + // the selecting message. + start("private", {skip_scrolling_selected_message: true}); return; } diff --git a/web/src/narrow.js b/web/src/narrow.js index 44c3a1cff8..d52110e7d8 100644 --- a/web/src/narrow.js +++ b/web/src/narrow.js @@ -484,6 +484,13 @@ export function activate(raw_operators, opts) { }); } + // Important: We need to consider opening the compose box + // before calling update_selection, so that the logic in + // recenter_view for positioning the currently selected + // message can take into account the space consumed by the + // open compose box. + compose_actions.on_narrow(opts); + if (select_immediately) { update_selection({ id_info, @@ -501,7 +508,6 @@ export function activate(raw_operators, opts) { handle_post_view_change(msg_list); - compose_actions.on_narrow(opts); unread_ui.update_unread_banner(); diff --git a/web/tests/narrow_activate.test.js b/web/tests/narrow_activate.test.js index fcb0be8ee9..ed77c01cd8 100644 --- a/web/tests/narrow_activate.test.js +++ b/web/tests/narrow_activate.test.js @@ -189,6 +189,7 @@ run_test("basics", ({override}) => { [message_feed_loading, "hide_indicators"], [message_lists, "save_pre_narrow_offset_for_reload"], [compose_banner, "clear_message_sent_banners"], + [compose_actions, "on_narrow"], [unread_ops, "process_visible"], [narrow_history, "save_narrow_state_and_flush"], [message_viewport, "stop_auto_scrolling"], @@ -200,7 +201,6 @@ run_test("basics", ({override}) => { [narrow_title, "update_narrow_title"], [left_sidebar_navigation_area, "handle_narrow_activated"], [stream_list, "handle_narrow_activated"], - [compose_actions, "on_narrow"], [compose_recipient, "handle_middle_pane_transition"], ]);