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.

inbox: Add page up/down support similar to recent topics.

Aman Agrawal9ab1a726a024
diff --git a/web/src/hotkey.js b/web/src/hotkey.js
index 2a573eeeafc..c4bf3769391 100644
--- a/web/src/hotkey.js
+++ b/web/src/hotkey.js
@@ -665,6 +665,8 @@ export function process_hotkey(e, hotkey) {
case "vim_down":
case "vim_left":
case "vim_right":
+ case "page_up":
+ case "page_down":
if (inbox_ui.is_in_focus()) {
return inbox_ui.change_focused_element(event_name);
}
diff --git a/web/src/inbox_ui.js b/web/src/inbox_ui.js
index bf614dcce8f..fa9affe9908 100644
--- a/web/src/inbox_ui.js
+++ b/web/src/inbox_ui.js
@@ -837,6 +837,48 @@ function is_muted_filter_focused() {
return current_focus_id === MUTED_FILTER_ID;
}
+function get_page_up_down_delta() {
+ const element_above = document.querySelector("#inbox-filters");
+ const element_down = document.querySelector("#compose");
+ const visible_top = element_above.getBoundingClientRect().bottom;
+ const visible_bottom = element_down.getBoundingClientRect().top;
+ // One usually wants PageDown to move what had been the bottom row
+ // to now be at the top, so one can be confident one will see
+ // every row using it. This offset helps achieve that goal.
+ //
+ // See navigate.amount_to_paginate for similar logic in the message feed.
+ const scrolling_reduction_to_maintain_context = 30;
+
+ const delta = visible_bottom - visible_top - scrolling_reduction_to_maintain_context;
+ return delta;
+}
+
+function page_up_navigation() {
+ const delta = get_page_up_down_delta();
+ const scroll_element = document.documentElement;
+ const new_scrollTop = scroll_element.scrollTop - delta;
+ if (new_scrollTop <= 0) {
+ row_focus = 0;
+ }
+ scroll_element.scrollTop = new_scrollTop;
+ set_list_focus();
+}
+
+function page_down_navigation() {
+ const delta = get_page_up_down_delta();
+ const scroll_element = document.documentElement;
+ const new_scrollTop = scroll_element.scrollTop + delta;
+ const $all_rows = get_all_rows();
+ const $last_row = $all_rows.last();
+ const last_row_bottom = $last_row.offset().top + $last_row.outerHeight();
+ // Move focus to last row if it is visible and we are at the bottom.
+ if (last_row_bottom <= new_scrollTop) {
+ row_focus = get_all_rows().length - 1;
+ }
+ scroll_element.scrollTop = new_scrollTop;
+ set_list_focus();
+}
+
export function change_focused_element(input_key) {
if (is_search_focused()) {
const textInput = $(`#${INBOX_SEARCH_ID}`).get(0);
@@ -911,6 +953,12 @@ export function change_focused_element(input_key) {
col_focus -= 1;
set_list_focus(input_key);
return true;
+ case "page_up":
+ page_up_navigation();
+ return true;
+ case "page_down":
+ page_down_navigation();
+ return true;
}
}