navigate: Move scroll_to_selected to message_viewport.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2023-10-07 00:01:37 -07:00
committed by Tim Abbott
parent 18bdfde9e7
commit b9fe1947f8
6 changed files with 28 additions and 29 deletions

View File

@@ -15,7 +15,6 @@ import * as message_lists from "./message_lists";
import * as message_scroll from "./message_scroll"; import * as message_scroll from "./message_scroll";
import * as message_viewport from "./message_viewport"; import * as message_viewport from "./message_viewport";
import * as narrow from "./narrow"; import * as narrow from "./narrow";
import * as navigate from "./navigate";
import * as overlays from "./overlays"; import * as overlays from "./overlays";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as popovers from "./popovers"; import * as popovers from "./popovers";
@@ -58,7 +57,7 @@ function show_all_message_view() {
narrow.deactivate(!(coming_from_recent_view || coming_from_inbox), is_actively_scrolling); narrow.deactivate(!(coming_from_recent_view || coming_from_inbox), is_actively_scrolling);
// We need to maybe scroll to the selected message // We need to maybe scroll to the selected message
// once we have the proper viewport set up // once we have the proper viewport set up
setTimeout(navigate.maybe_scroll_to_selected, 0); setTimeout(message_viewport.maybe_scroll_to_selected, 0);
} }
export function set_hash_to_default_view() { export function set_hash_to_default_view() {

View File

@@ -483,6 +483,28 @@ export function keep_pointer_in_view() {
message_lists.current.select_id(rows.id($next_row), {from_scroll: true}); message_lists.current.select_id(rows.id($next_row), {from_scroll: true});
} }
export function scroll_to_selected() {
const $selected_row = message_lists.current.selected_row();
if ($selected_row && $selected_row.length !== 0) {
recenter_view($selected_row);
}
}
export let scroll_to_selected_planned = false;
export function plan_scroll_to_selected() {
scroll_to_selected_planned = true;
}
export function maybe_scroll_to_selected() {
// If we have made a plan to scroll to the selected message but
// deferred doing so, do so here.
if (scroll_to_selected_planned) {
scroll_to_selected();
scroll_to_selected_planned = false;
}
}
export function initialize() { export function initialize() {
$jwindow = $(window); $jwindow = $(window);
$scroll_container = $("html"); $scroll_container = $("html");

View File

@@ -116,25 +116,3 @@ export function page_down() {
page_down_the_right_amount(); page_down_the_right_amount();
} }
} }
export function scroll_to_selected() {
const $selected_row = message_lists.current.selected_row();
if ($selected_row && $selected_row.length !== 0) {
message_viewport.recenter_view($selected_row);
}
}
let scroll_to_selected_planned = false;
export function plan_scroll_to_selected() {
scroll_to_selected_planned = true;
}
export function maybe_scroll_to_selected() {
// If we have made a plan to scroll to the selected message but
// deferred doing so, do so here.
if (scroll_to_selected_planned) {
scroll_to_selected();
scroll_to_selected_planned = false;
}
}

View File

@@ -3,7 +3,7 @@ import $ from "jquery";
import * as compose_ui from "./compose_ui"; import * as compose_ui from "./compose_ui";
import * as condense from "./condense"; import * as condense from "./condense";
import * as message_lists from "./message_lists"; import * as message_lists from "./message_lists";
import * as navigate from "./navigate"; import * as message_viewport from "./message_viewport";
import * as popover_menus from "./popover_menus"; import * as popover_menus from "./popover_menus";
import * as popovers from "./popovers"; import * as popovers from "./popovers";
import * as resize from "./resize"; import * as resize from "./resize";
@@ -42,6 +42,6 @@ export function handler() {
popover_menus.set_suppress_scroll_hide(); popover_menus.set_suppress_scroll_hide();
} }
navigate.scroll_to_selected(); message_viewport.scroll_to_selected();
} }
} }

View File

@@ -677,7 +677,7 @@ export function initialize_everything() {
desktop_notifications.initialize(); desktop_notifications.initialize();
audible_notifications.initialize(); audible_notifications.initialize();
compose_notifications.initialize({ compose_notifications.initialize({
on_click_scroll_to_selected: navigate.scroll_to_selected, on_click_scroll_to_selected: message_viewport.scroll_to_selected,
on_narrow_to_recipient(message_id) { on_narrow_to_recipient(message_id) {
narrow.by_topic(message_id, {trigger: "compose_notification"}); narrow.by_topic(message_id, {trigger: "compose_notification"});
}, },

View File

@@ -3,9 +3,9 @@ import $ from "jquery";
import * as compose_recipient from "./compose_recipient"; import * as compose_recipient from "./compose_recipient";
import * as message_lists from "./message_lists"; import * as message_lists from "./message_lists";
import * as message_view_header from "./message_view_header"; import * as message_view_header from "./message_view_header";
import * as message_viewport from "./message_viewport";
import * as narrow_state from "./narrow_state"; import * as narrow_state from "./narrow_state";
import * as narrow_title from "./narrow_title"; import * as narrow_title from "./narrow_title";
import * as navigate from "./navigate";
import * as pm_list from "./pm_list"; import * as pm_list from "./pm_list";
import * as resize from "./resize"; import * as resize from "./resize";
import * as search from "./search"; import * as search from "./search";
@@ -71,5 +71,5 @@ export function hide(opts) {
// This makes sure user lands on the selected message // This makes sure user lands on the selected message
// and not always at the top of the narrow. // and not always at the top of the narrow.
navigate.plan_scroll_to_selected(); message_viewport.plan_scroll_to_selected();
} }