Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_view: Scroll to date should show the message on top.
Shubham Padiac1cc4dd3efd4
diff --git a/web/src/message_view.ts b/web/src/message_view.tsindex 112f9f4bfff..9824e03be07 100644--- a/web/src/message_view.ts+++ b/web/src/message_view.ts@@ -324,6 +324,13 @@ function handle_post_message_list_change(compose_recipient.handle_middle_pane_transition();}+function get_selected_message_top_offset(): number {+ const navbar_height = $("#navbar-fixed-container").height()!;+ // 30px height + 10px top margin.+ const sticky_header_outer_height = 40;+ return navbar_height + sticky_header_outer_height;+}+export function try_rendering_locally_for_same_narrow(filter: Filter,opts: ShowMessageViewOpts,@@ -701,12 +708,8 @@ export let show = (raw_terms: NarrowTerm[], show_opts: ShowMessageViewOpts): voiconst $row = message_lists.current.get_row(opts.then_select_id);if ($row.length > 0) {const row_props = $row.get_offset_to_window();- const navbar_height = $("#navbar-fixed-container").height()!;- // 30px height + 10px top margin.const compose_box_top = $("#compose").get_offset_to_window().top;- const sticky_header_outer_height = 40;- const min_height_for_message_top_visible =- navbar_height + sticky_header_outer_height;+ const min_height_for_message_top_visible = get_selected_message_top_offset();if (// We want to keep the selected message in the same scroll position after the narrow changes if possible.@@ -992,11 +995,15 @@ function navigate_to_anchor_message(opts: {function select_msg_id(msg_id: number, select_opts?: SelectIdOpts): void {assert(message_lists.current !== undefined);- message_lists.current.select_id(msg_id, {+ const updated_select_opts = {then_scroll: true,from_scroll: false,...select_opts,- });+ };+ if (anchor === "date") {+ updated_select_opts.target_scroll_offset = get_selected_message_top_offset();+ }+ message_lists.current.select_id(msg_id, updated_select_opts);}function select_anchor_using_data(data: MessageListData): void {diff --git a/web/tests/message_view.test.cjs b/web/tests/message_view.test.cjsindex 7cedce72e17..76c5a990e76 100644--- a/web/tests/message_view.test.cjs+++ b/web/tests/message_view.test.cjs@@ -929,12 +929,15 @@ run_test("fast_track_current_msg_list_to_anchor date", ({override}) => {selected = {id, opts};};message_lists.current = list;+ $("#navbar-fixed-container").set_height(50);+ // Date jumps should place the selected message below the sticky+ // message header, increasing the target scroll offset by 40px.const in_range = new Date(150 * 1000).toISOString();message_view.fast_track_current_msg_list_to_anchor("date", in_range);assert.deepEqual(selected, {id: 102,- opts: {then_scroll: true, from_scroll: false},+ opts: {then_scroll: true, from_scroll: false, target_scroll_offset: 90},});list.data.fetch_status.finish_older_batch({@@ -946,7 +949,7 @@ run_test("fast_track_current_msg_list_to_anchor date", ({override}) => {message_view.fast_track_current_msg_list_to_anchor("date", before_range);assert.deepEqual(selected, {id: 101,- opts: {then_scroll: true, from_scroll: false},+ opts: {then_scroll: true, from_scroll: false, target_scroll_offset: 90},});// If we have not found the oldest message, and the anchor timestamp is@@ -982,7 +985,12 @@ run_test("fast_track_current_msg_list_to_anchor date", ({override}) => {assert.equal(load_messages_anchor, "date");assert.deepEqual(selected, {id: 100,- opts: {then_scroll: true, from_scroll: false, force_rerender: true},+ opts: {+ then_scroll: true,+ from_scroll: false,+ force_rerender: true,+ target_scroll_offset: 90,+ },});// Message 104 is not in the list so we need to fetch it from the API@@ -1010,7 +1018,12 @@ run_test("fast_track_current_msg_list_to_anchor date", ({override}) => {assert.equal(load_messages_anchor, "date");assert.deepEqual(selected, {id: 104,- opts: {then_scroll: true, from_scroll: false, force_rerender: true},+ opts: {+ then_scroll: true,+ from_scroll: false,+ force_rerender: true,+ target_scroll_offset: 90,+ },});// If we have found the newest message, having anchor_date in@@ -1024,7 +1037,7 @@ run_test("fast_track_current_msg_list_to_anchor date", ({override}) => {message_view.fast_track_current_msg_list_to_anchor("date", future_range);assert.deepEqual(selected, {id: 104,- opts: {then_scroll: true, from_scroll: false},+ opts: {then_scroll: true, from_scroll: false, target_scroll_offset: 90},});assert.equal(load_messages_calls, 0);