From 0e5c6ec5b98c5c435e429ba3f0f5c5f300c572ff Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Wed, 20 Sep 2023 05:35:46 +0000 Subject: [PATCH] inbox: Fix inbox scrolled to top when returning from other narrows. This has to do with narrows and inbox view sharing the same scrolling container. --- web/src/inbox_ui.js | 5 ++++- web/src/message_edit.js | 13 +++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/web/src/inbox_ui.js b/web/src/inbox_ui.js index 43601969c2..ecbc3c4d3f 100644 --- a/web/src/inbox_ui.js +++ b/web/src/inbox_ui.js @@ -462,7 +462,10 @@ export function complete_rerender() { ); update_filters(); show_empty_inbox_text(has_visible_unreads); - + // If the focus is not on the inbox rows, the inbox view scrolls + // downwhen moving from other views to the inbox view. To avoid + // this, we scroll to top before restoring focus. + $("html").scrollTop(0); setTimeout(() => { // We don't want to focus on simplebar ever. $("#inbox-list .simplebar-content-wrapper").attr("tabindex", "-1"); diff --git a/web/src/message_edit.js b/web/src/message_edit.js index 9e280248ee..d7c73a1940 100644 --- a/web/src/message_edit.js +++ b/web/src/message_edit.js @@ -719,12 +719,17 @@ export function toggle_resolve_topic( url: "/json/messages/" + message_id, data: request, success() { - const $spinner = $row.find(".toggle_resolve_topic_spinner"); - loading.destroy_indicator($spinner); + if ($row) { + const $spinner = $row.find(".toggle_resolve_topic_spinner"); + loading.destroy_indicator($spinner); + } }, error(xhr) { - const $spinner = $row.find(".toggle_resolve_topic_spinner"); - loading.destroy_indicator($spinner); + if ($row) { + const $spinner = $row.find(".toggle_resolve_topic_spinner"); + loading.destroy_indicator($spinner); + } + if (xhr.responseJSON) { if (xhr.responseJSON.code === "MOVE_MESSAGES_TIME_LIMIT_EXCEEDED") { handle_resolve_topic_failure_due_to_time_limit(topic_is_resolved);