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_topics: Move is_in_focus to UI module.

Tim Abbott0e2bce3bcba8
diff --git a/web/src/hotkey.js b/web/src/hotkey.js
index 5b5605bdc84..f55a7651bad 100644
--- a/web/src/hotkey.js
+++ b/web/src/hotkey.js
@@ -236,7 +236,7 @@ export function in_content_editable_widget(e) {
// Returns true if we handled it, false if the browser should.
export function process_escape_key(e) {
if (
- recent_topics_util.is_in_focus() &&
+ recent_topics_ui.is_in_focus() &&
// This will return false if `e.target` is not
// any of the recent topics elements by design.
recent_topics_ui.change_focused_element($(e.target), "escape")
@@ -622,7 +622,7 @@ export function process_hotkey(e, hotkey) {
case "tab":
case "shift_tab":
case "open_recent_topics":
- if (recent_topics_util.is_in_focus()) {
+ if (recent_topics_ui.is_in_focus()) {
return recent_topics_ui.change_focused_element($(e.target), event_name);
}
}
diff --git a/web/src/recent_topics_ui.js b/web/src/recent_topics_ui.js
index 8f821b1f880..bb4d4f9fa6d 100644
--- a/web/src/recent_topics_ui.js
+++ b/web/src/recent_topics_ui.js
@@ -9,6 +9,7 @@ import render_user_with_status_icon from "../templates/user_with_status_icon.hbs
import * as blueslip from "./blueslip";
import * as buddy_data from "./buddy_data";
import * as compose_closed_ui from "./compose_closed_ui";
+import * as compose_state from "./compose_state";
import * as hash_util from "./hash_util";
import {$t} from "./i18n";
import * as left_sidebar_navigation_area from "./left_sidebar_navigation_area";
@@ -22,19 +23,14 @@ import * as muted_users from "./muted_users";
import * as narrow from "./narrow";
import * as narrow_state from "./narrow_state";
import * as navigate from "./navigate";
+import * as overlays from "./overlays";
import {page_params} from "./page_params";
import * as people from "./people";
import * as pm_list from "./pm_list";
import * as popovers from "./popovers";
import * as recent_senders from "./recent_senders";
import {get, process_message, topics} from "./recent_topics_data";
-import {
- get_key_from_message,
- get_topic_key,
- is_in_focus,
- is_visible,
- set_visible,
-} from "./recent_topics_util";
+import {get_key_from_message, get_topic_key, is_visible, set_visible} from "./recent_topics_util";
import * as resize from "./resize";
import * as scroll_util from "./scroll_util";
import * as search from "./search";
@@ -108,6 +104,17 @@ export function save_filters() {
ls.set(ls_key, [...filters]);
}
+export function is_in_focus() {
+ // Check if user is focused on recent topics.
+ return (
+ is_visible() &&
+ !compose_state.composing() &&
+ !popovers.any_active() &&
+ !overlays.is_overlay_or_modal_open() &&
+ !$(".home-page-input").is(":focus")
+ );
+}
+
export function set_default_focus() {
// If at any point we are confused about the currently
// focused element, we switch focus to search.
diff --git a/web/src/recent_topics_util.js b/web/src/recent_topics_util.js
index 979eb861eb7..31951ba187d 100644
--- a/web/src/recent_topics_util.js
+++ b/web/src/recent_topics_util.js
@@ -1,9 +1,3 @@
-import $ from "jquery";
-
-import * as compose_state from "./compose_state";
-import * as overlays from "./overlays";
-import * as popovers from "./popovers";
-
let is_rt_visible = false;
export function set_visible(value) {
@@ -14,18 +8,6 @@ export function is_visible() {
return is_rt_visible;
}
-export function is_in_focus() {
- // Check if user is focused on
- // recent topics.
- return (
- is_visible() &&
- !compose_state.composing() &&
- !popovers.any_active() &&
- !overlays.is_overlay_or_modal_open() &&
- !$(".home-page-input").is(":focus")
- );
-}
-
export function get_topic_key(stream_id, topic) {
return stream_id + ":" + topic.toLowerCase();
}
diff --git a/web/tests/hotkey.test.js b/web/tests/hotkey.test.js
index fe9e8088cc3..cb5cae0d020 100644
--- a/web/tests/hotkey.test.js
+++ b/web/tests/hotkey.test.js
@@ -84,7 +84,7 @@ mock_esm("../src/hotspots", {
is_open: () => false,
});
-mock_esm("../src/recent_topics_util", {
+mock_esm("../src/recent_topics_ui", {
is_in_focus: () => false,
});