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.

recent_view: Skip last_visited_topic restoration on large position shift.

Aman Agrawal2320c88a08db
diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.ts
index 768fa1d8264..ec43f61dcf4 100644
--- a/web/src/recent_view_ui.ts
+++ b/web/src/recent_view_ui.ts
@@ -501,7 +501,18 @@ export function revive_current_focus(): boolean {
const last_visited_topic_index = current_list.findIndex(
(topic) => topic.last_msg_id === topic_last_msg_id,
);
- if (last_visited_topic_index !== -1) {
+ // Only restore focus to the topic if it hasn't moved
+ // too far from where the user left off. A topic can
+ // shift significantly due to new messages arriving
+ // (sorted by time), topic renames (sorted by topic),
+ // or marking as read (sorted by unread count), which
+ // would disorient the user by jumping them far from
+ // their previous scroll position.
+ const max_focus_shift = 10;
+ if (
+ last_visited_topic_index !== -1 &&
+ Math.abs(last_visited_topic_index - row_focus) <= max_focus_shift
+ ) {
row_focus = last_visited_topic_index;
}
}