mirror of https://github.com/zulip/zulip.git
message_scroll: Move state flags to new module message_scroll_state.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
73507ee2ae
commit
457544e0d2
|
@ -125,6 +125,7 @@ EXEMPT_FILES = make_set(
|
||||||
"web/src/message_lists.js",
|
"web/src/message_lists.js",
|
||||||
"web/src/message_live_update.js",
|
"web/src/message_live_update.js",
|
||||||
"web/src/message_scroll.js",
|
"web/src/message_scroll.js",
|
||||||
|
"web/src/message_scroll_state.ts",
|
||||||
"web/src/message_util.js",
|
"web/src/message_util.js",
|
||||||
"web/src/message_view_header.js",
|
"web/src/message_view_header.js",
|
||||||
"web/src/message_viewport.js",
|
"web/src/message_viewport.js",
|
||||||
|
|
|
@ -27,7 +27,7 @@ import * as list_util from "./list_util";
|
||||||
import * as message_edit from "./message_edit";
|
import * as message_edit from "./message_edit";
|
||||||
import * as message_edit_history from "./message_edit_history";
|
import * as message_edit_history from "./message_edit_history";
|
||||||
import * as message_lists from "./message_lists";
|
import * as message_lists from "./message_lists";
|
||||||
import * as message_scroll from "./message_scroll";
|
import * as message_scroll_state from "./message_scroll_state";
|
||||||
import * as narrow from "./narrow";
|
import * as narrow from "./narrow";
|
||||||
import * as narrow_state from "./narrow_state";
|
import * as narrow_state from "./narrow_state";
|
||||||
import * as navigate from "./navigate";
|
import * as navigate from "./navigate";
|
||||||
|
@ -958,33 +958,33 @@ export function process_hotkey(e, hotkey) {
|
||||||
switch (event_name) {
|
switch (event_name) {
|
||||||
case "down_arrow":
|
case "down_arrow":
|
||||||
case "vim_down":
|
case "vim_down":
|
||||||
message_scroll.mark_keyboard_triggered_current_scroll();
|
message_scroll_state.set_keyboard_triggered_current_scroll(true);
|
||||||
navigate.down(true); // with_centering
|
navigate.down(true); // with_centering
|
||||||
return true;
|
return true;
|
||||||
case "up_arrow":
|
case "up_arrow":
|
||||||
case "vim_up":
|
case "vim_up":
|
||||||
message_scroll.mark_keyboard_triggered_current_scroll();
|
message_scroll_state.set_keyboard_triggered_current_scroll(true);
|
||||||
navigate.up();
|
navigate.up();
|
||||||
return true;
|
return true;
|
||||||
case "home":
|
case "home":
|
||||||
message_scroll.mark_keyboard_triggered_current_scroll();
|
message_scroll_state.set_keyboard_triggered_current_scroll(true);
|
||||||
navigate.to_home();
|
navigate.to_home();
|
||||||
return true;
|
return true;
|
||||||
case "end":
|
case "end":
|
||||||
case "G_end":
|
case "G_end":
|
||||||
message_scroll.mark_keyboard_triggered_current_scroll();
|
message_scroll_state.set_keyboard_triggered_current_scroll(true);
|
||||||
navigate.to_end();
|
navigate.to_end();
|
||||||
return true;
|
return true;
|
||||||
case "page_up":
|
case "page_up":
|
||||||
case "vim_page_up":
|
case "vim_page_up":
|
||||||
case "shift_spacebar":
|
case "shift_spacebar":
|
||||||
message_scroll.mark_keyboard_triggered_current_scroll();
|
message_scroll_state.set_keyboard_triggered_current_scroll(true);
|
||||||
navigate.page_up();
|
navigate.page_up();
|
||||||
return true;
|
return true;
|
||||||
case "page_down":
|
case "page_down":
|
||||||
case "vim_page_down":
|
case "vim_page_down":
|
||||||
case "spacebar":
|
case "spacebar":
|
||||||
message_scroll.mark_keyboard_triggered_current_scroll();
|
message_scroll_state.set_keyboard_triggered_current_scroll(true);
|
||||||
navigate.page_down();
|
navigate.page_down();
|
||||||
return true;
|
return true;
|
||||||
case "copy_with_c":
|
case "copy_with_c":
|
||||||
|
|
|
@ -4,6 +4,7 @@ import _ from "lodash";
|
||||||
import * as compose_banner from "./compose_banner";
|
import * as compose_banner from "./compose_banner";
|
||||||
import * as message_fetch from "./message_fetch";
|
import * as message_fetch from "./message_fetch";
|
||||||
import * as message_lists from "./message_lists";
|
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 message_viewport from "./message_viewport";
|
||||||
import * as narrow_state from "./narrow_state";
|
import * as narrow_state from "./narrow_state";
|
||||||
import * as unread from "./unread";
|
import * as unread from "./unread";
|
||||||
|
@ -12,22 +13,6 @@ import * as unread_ui from "./unread_ui";
|
||||||
|
|
||||||
let actively_scrolling = false;
|
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;
|
let hide_scroll_to_bottom_timer;
|
||||||
export function hide_scroll_to_bottom() {
|
export function hide_scroll_to_bottom() {
|
||||||
const $show_scroll_to_bottom_button = $("#scroll-to-bottom-button-container");
|
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();
|
message_viewport.keep_pointer_in_view();
|
||||||
} else {
|
} else {
|
||||||
update_selection_on_next_scroll = true;
|
message_scroll_state.set_update_selection_on_next_scroll(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message_viewport.at_top()) {
|
if (message_viewport.at_top()) {
|
||||||
|
@ -125,10 +110,10 @@ function scroll_finish() {
|
||||||
|
|
||||||
// Don't present the "scroll to bottom" widget if the current
|
// Don't present the "scroll to bottom" widget if the current
|
||||||
// scroll was triggered by the keyboard.
|
// scroll was triggered by the keyboard.
|
||||||
if (!keyboard_triggered_current_scroll) {
|
if (!message_scroll_state.keyboard_triggered_current_scroll) {
|
||||||
show_scroll_to_bottom_button();
|
show_scroll_to_bottom_button();
|
||||||
}
|
}
|
||||||
keyboard_triggered_current_scroll = false;
|
message_scroll_state.set_keyboard_triggered_current_scroll(false);
|
||||||
|
|
||||||
clearTimeout(scroll_timer);
|
clearTimeout(scroll_timer);
|
||||||
scroll_timer = setTimeout(scroll_finished, 100);
|
scroll_timer = setTimeout(scroll_finished, 100);
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Tracks whether the next scroll that will complete is initiated by
|
||||||
|
// code, not the user, and thus should avoid moving the selected
|
||||||
|
// message.
|
||||||
|
export let update_selection_on_next_scroll = true;
|
||||||
|
|
||||||
|
export function set_update_selection_on_next_scroll(value: boolean): void {
|
||||||
|
update_selection_on_next_scroll = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whether a keyboard shortcut is triggering a message feed scroll event.
|
||||||
|
export let keyboard_triggered_current_scroll = false;
|
||||||
|
|
||||||
|
export function set_keyboard_triggered_current_scroll(value: boolean): void {
|
||||||
|
keyboard_triggered_current_scroll = value;
|
||||||
|
}
|
|
@ -2,7 +2,7 @@ import $ from "jquery";
|
||||||
|
|
||||||
import * as blueslip from "./blueslip";
|
import * as blueslip from "./blueslip";
|
||||||
import * as message_lists from "./message_lists";
|
import * as message_lists from "./message_lists";
|
||||||
import * as message_scroll from "./message_scroll";
|
import * as message_scroll_state from "./message_scroll_state";
|
||||||
import * as popover_menus from "./popover_menus";
|
import * as popover_menus from "./popover_menus";
|
||||||
import * as rows from "./rows";
|
import * as rows from "./rows";
|
||||||
import * as util from "./util";
|
import * as util from "./util";
|
||||||
|
@ -156,7 +156,7 @@ export function set_message_position(message_top, message_height, viewport_info,
|
||||||
|
|
||||||
const new_scroll_top = message_top - message_offset;
|
const new_scroll_top = message_top - message_offset;
|
||||||
|
|
||||||
message_scroll.suppress_selection_update_on_next_scroll();
|
message_scroll_state.set_update_selection_on_next_scroll(false);
|
||||||
scrollTop(new_scroll_top);
|
scrollTop(new_scroll_top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,7 +334,7 @@ export function stop_auto_scrolling() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function system_initiated_animate_scroll(scroll_amount) {
|
export function system_initiated_animate_scroll(scroll_amount) {
|
||||||
message_scroll.suppress_selection_update_on_next_scroll();
|
message_scroll_state.set_update_selection_on_next_scroll(false);
|
||||||
const viewport_offset = scrollTop();
|
const viewport_offset = scrollTop();
|
||||||
in_stoppable_autoscroll = true;
|
in_stoppable_autoscroll = true;
|
||||||
$scroll_container.animate({
|
$scroll_container.animate({
|
||||||
|
@ -346,7 +346,7 @@ export function system_initiated_animate_scroll(scroll_amount) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function user_initiated_animate_scroll(scroll_amount) {
|
export function user_initiated_animate_scroll(scroll_amount) {
|
||||||
message_scroll.suppress_selection_update_on_next_scroll();
|
message_scroll_state.set_update_selection_on_next_scroll(false);
|
||||||
in_stoppable_autoscroll = false; // defensive
|
in_stoppable_autoscroll = false; // defensive
|
||||||
|
|
||||||
const viewport_offset = scrollTop();
|
const viewport_offset = scrollTop();
|
||||||
|
|
Loading…
Reference in New Issue