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.

hashchange: Restore narrow state on `escape` keypress to `feed`.

Aman Agrawalf07ed8b6b309
diff --git a/web/src/hashchange.js b/web/src/hashchange.js
index 1177f1c7767..6593501736d 100644
--- a/web/src/hashchange.js
+++ b/web/src/hashchange.js
@@ -72,7 +72,7 @@ function is_somebody_else_profile_open() {
);
}
-export function set_hash_to_home_view() {
+export function set_hash_to_home_view(triggered_by_escape_key = false) {
let home_view_hash = `#${user_settings.web_home_view}`;
if (home_view_hash === "#recent_topics") {
home_view_hash = "#recent";
@@ -83,6 +83,20 @@ export function set_hash_to_home_view() {
}
if (window.location.hash !== home_view_hash) {
+ const hash_before_current = browser_history.old_hash();
+ if (
+ triggered_by_escape_key &&
+ home_view_hash === "#feed" &&
+ (hash_before_current === "" || hash_before_current === "#feed")
+ ) {
+ // If the previous view was the user's Combined Feed home
+ // view, and this change was triggered by escape keypress,
+ // then we simulate the back button in order to reuse
+ // existing code for restoring the user's scroll position.
+ window.history.back();
+ return;
+ }
+
// We want to set URL with no hash here. It is not possible
// to do so with `window.location.hash` since it will set an empty
// hash. So, we use `pushState` which simply updates the current URL
diff --git a/web/src/hotkey.js b/web/src/hotkey.js
index 0071db5bebc..2a493cda11a 100644
--- a/web/src/hotkey.js
+++ b/web/src/hotkey.js
@@ -385,7 +385,8 @@ export function process_escape_key(e) {
/* The Ctrl+[ hotkey navigates to the home view
* unconditionally; Esc's behavior depends on a setting. */
if (user_settings.web_escape_navigates_to_home_view || e.which === 219) {
- hashchange.set_hash_to_home_view();
+ const triggered_by_escape_key = true;
+ hashchange.set_hash_to_home_view(triggered_by_escape_key);
return true;
}