Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

views_util: Extract the page height without its bottom padding.

Aman Agrawalafedcf89ae77
diff --git a/web/src/views_util.ts b/web/src/views_util.ts
index bcb2ad8278b..9da52cc1c66 100644
--- a/web/src/views_util.ts
+++ b/web/src/views_util.ts
@@ -198,18 +198,22 @@ export function find_first_row_index_at_or_below(rows: Element[], y: number): nu
return index === -1 ? undefined : index;
}
+// We allocate `--max-unmaximized-compose-height` in empty space
+// below the last rendered row in recent view.
+function get_scroll_height_without_bottom_padding(): number {
+ const compose_max_height = $(":root").css("--max-unmaximized-compose-height");
+ assert(typeof compose_max_height === "string");
+ return document.body.scrollHeight - Number.parseInt(compose_max_height, 10);
+}
+
export function is_scroll_position_for_render(): boolean {
const scroll_position = window.scrollY;
const window_height = window.innerHeight;
- // We allocate `--max-unmaximized-compose-height` in empty space
- // below the last rendered row in recent view.
- //
- // We don't want user to see this empty space until there are no
- // new rows to render when the user is scrolling to the bottom of
- // the view. So, we render new rows when user has scrolled 2 / 3
- // of (the total scrollable height - the empty space).
- const compose_max_height = $(":root").css("--max-unmaximized-compose-height");
- assert(typeof compose_max_height === "string");
- const scroll_max = document.body.scrollHeight - Number.parseInt(compose_max_height, 10);
+ // We don't want user to see the empty space below the last rendered
+ // row until there are no new rows to render when the user is
+ // scrolling to the bottom of the view. So, we render new rows when
+ // user has scrolled 2 / 3 of (the total scrollable height - the
+ // empty space).
+ const scroll_max = get_scroll_height_without_bottom_padding();
return scroll_position + window_height >= (2 / 3) * scroll_max;
}