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.

search_pill: Avoid jQuery sizzle extension :visible.

Anders Kaseorgc248459af240
diff --git a/web/src/search.ts b/web/src/search.ts
index 338b37422cf..bd819bd6e50 100644
--- a/web/src/search.ts
+++ b/web/src/search.ts
@@ -75,7 +75,12 @@ function narrow_or_search_for_term({on_narrow_search}: {on_narrow_search: OnNarr
// because convert_to_pill_on_enter is false.
assert(search_pill_widget !== null);
search_pill_widget.clear(true);
- search_pill.set_search_bar_contents(terms, search_pill_widget, set_search_bar_text);
+ search_pill.set_search_bar_contents(
+ terms,
+ search_pill_widget,
+ search_typeahead.shown,
+ set_search_bar_text,
+ );
on_narrow_search(terms, {trigger: "search"});
// It's sort of annoying that this is not in a position to
@@ -220,6 +225,7 @@ export function initialize(opts: {on_narrow_search: OnNarrowSearch}): void {
search_pill.set_search_bar_contents(
search_terms,
search_pill_widget,
+ search_typeahead.shown,
set_search_bar_text,
);
narrow_to_search_contents_with_search_bar_open();
@@ -385,6 +391,7 @@ function reset_searchbox(clear = false): void {
search_pill.set_search_bar_contents(
narrow_state.search_terms(),
search_pill_widget,
+ search_typeahead.shown,
set_search_bar_text,
);
}
diff --git a/web/src/search_pill.ts b/web/src/search_pill.ts
index 5cbb3623cdb..fc6241e5fbb 100644
--- a/web/src/search_pill.ts
+++ b/web/src/search_pill.ts
@@ -171,6 +171,7 @@ const user_pill_operators = new Set(["dm", "dm-including", "sender"]);
export function set_search_bar_contents(
search_terms: NarrowTerm[],
pill_widget: SearchPillWidget,
+ is_typeahead_visible: boolean,
set_search_bar_text: (text: string) => void,
): void {
pill_widget.clear(true);
@@ -189,18 +190,16 @@ export function set_search_bar_contents(
// typeahead to show operand suggestions.
// Note: We make a pill for `topic:` as it represents empty string topic
// except the case where it suggests `topic` operator.
- if (input.at(-1) === ":" && term.operand === "" && term === search_terms.at(-1)) {
- const is_topic_operator_suggestion = (): boolean => {
- const is_typeahead_visible = $("#searchbox_form .typeahead").is(":visible");
- return (
- is_typeahead_visible &&
- $("#searchbox_form .typeahead-item.active .empty-topic-display").length === 0
- );
- };
- if (term.operator !== "topic" || is_topic_operator_suggestion()) {
- partial_pill = input;
- continue;
- }
+ if (
+ input.at(-1) === ":" &&
+ term.operand === "" &&
+ term === search_terms.at(-1) &&
+ (term.operator !== "topic" ||
+ (is_typeahead_visible &&
+ $("#searchbox_form .typeahead-item.active .empty-topic-display").length === 0))
+ ) {
+ partial_pill = input;
+ continue;
}
if (!Filter.is_valid_search_term(term)) {
diff --git a/web/tests/search.test.cjs b/web/tests/search.test.cjs
index 5398b636c17..a1471c8e3bf 100644
--- a/web/tests/search.test.cjs
+++ b/web/tests/search.test.cjs
@@ -232,6 +232,7 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {
search_pill.set_search_bar_contents(
terms,
search.search_pill_widget,
+ false,
$search_query_box.text,
);
};
@@ -315,6 +316,7 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {
search_pill.set_search_bar_contents(
terms,
search.search_pill_widget,
+ false,
$search_query_box.text,
);
};