Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
recent_view: Find the row at the center by position, like Inbox.
Aman Agrawal9d3ed9804ec8
diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.tsindex dfeaa0bb895..b5f410ff355 100644--- a/web/src/recent_view_ui.ts+++ b/web/src/recent_view_ui.ts@@ -1605,25 +1605,13 @@ function recenter_focus_if_off_screen(): void {}if (topic_offset !== "visible") {- // Get the element at the center of the table.+ // Get the row at the center of the table.const thead_props = util.the($("#recent-view-table-headers")).getBoundingClientRect();const compose_top = window.innerHeight - $("#compose").outerHeight(true)!;- const topic_center_x = (thead_props.left + thead_props.right) / 2;const topic_center_y = (thead_props.bottom + compose_top) / 2;-- const topic_element = views_util.find_element_at_point(- topic_center_x,- topic_center_y,- "#recent-view-content-tbody",- );- if (topic_element === undefined) {- // The table is too short for there to be a topic row element- // at the center of the table region; in that case, we just- // select the last element.- row_focus = $topic_rows.length - 1;- } else {- row_focus = $topic_rows.index($(topic_element).closest("tr")[0]);- }+ row_focus =+ views_util.find_first_row_index_at_or_below($topic_rows.toArray(), topic_center_y) ??+ $topic_rows.length - 1;set_table_focus(row_focus, col_focus);}diff --git a/web/src/views_util.ts b/web/src/views_util.tsindex ecfeb464c18..bcb2ad8278b 100644--- a/web/src/views_util.ts+++ b/web/src/views_util.ts@@ -189,24 +189,6 @@ export function is_in_focus(): boolean {);}-export function find_element_at_point(- x: number,- y: number,- container_selector: string,-): Element | undefined {- // When the view is obscured by a modal, overlay, popover, etc.- // `elementFromPoint` would return the covering element. Use- // `elementsFromPoint` to search through the full element stack- // and find the matching element beneath it.- const elements = document.elementsFromPoint(x, y);- for (const element of elements) {- if (element.closest(container_selector) !== null) {- return element;- }- }- return undefined;-}-export function find_first_row_index_at_or_below(rows: Element[], y: number): number | undefined {// Returns the index of the first row whose bottom edge is below// the viewport coordinate `y` (the row containing `y`, or else the