message_scroll: Move state flags to new module message_scroll_state.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2023-10-02 14:16:51 -07:00
committed by Tim Abbott
parent 73507ee2ae
commit 457544e0d2
5 changed files with 32 additions and 31 deletions

View File

@@ -4,6 +4,7 @@ import _ from "lodash";
import * as compose_banner from "./compose_banner";
import * as message_fetch from "./message_fetch";
import * as message_lists from "./message_lists";
import * as message_scroll_state from "./message_scroll_state";
import * as message_viewport from "./message_viewport";
import * as narrow_state from "./narrow_state";
import * as unread from "./unread";
@@ -12,22 +13,6 @@ import * as unread_ui from "./unread_ui";
let actively_scrolling = false;
// Tracks whether the next scroll that will complete is initiated by
// code, not the user, and thus should avoid moving the selected
// message.
let update_selection_on_next_scroll = true;
export function suppress_selection_update_on_next_scroll() {
update_selection_on_next_scroll = false;
}
// Whether a keyboard shortcut is triggering a message feed scroll event.
let keyboard_triggered_current_scroll = false;
export function mark_keyboard_triggered_current_scroll() {
keyboard_triggered_current_scroll = true;
}
let hide_scroll_to_bottom_timer;
export function hide_scroll_to_bottom() {
const $show_scroll_to_bottom_button = $("#scroll-to-bottom-button-container");
@@ -94,10 +79,10 @@ export function scroll_finished() {
}
}
if (update_selection_on_next_scroll) {
if (message_scroll_state.update_selection_on_next_scroll) {
message_viewport.keep_pointer_in_view();
} else {
update_selection_on_next_scroll = true;
message_scroll_state.set_update_selection_on_next_scroll(true);
}
if (message_viewport.at_top()) {
@@ -125,10 +110,10 @@ function scroll_finish() {
// Don't present the "scroll to bottom" widget if the current
// scroll was triggered by the keyboard.
if (!keyboard_triggered_current_scroll) {
if (!message_scroll_state.keyboard_triggered_current_scroll) {
show_scroll_to_bottom_button();
}
keyboard_triggered_current_scroll = false;
message_scroll_state.set_keyboard_triggered_current_scroll(false);
clearTimeout(scroll_timer);
scroll_timer = setTimeout(scroll_finished, 100);