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: Share the combined pill attempt for empty topic operands.

Evy Kassirer1f09b7808735
diff --git a/web/src/search_pill.ts b/web/src/search_pill.ts
index 484384bd329..501aa47caef 100644
--- a/web/src/search_pill.ts
+++ b/web/src/search_pill.ts
@@ -221,49 +221,29 @@ export function generate_pills_html(suggestion: Suggestion, text_query: string):
case "sender":
return search_user_pill_data_from_term(narrow_term);
case "topic": {
- if (search_pill.operand === "") {
- // There are three variants of this suggestion state:
- //
- // (1) This is an already formed pill, i.e. not in the text input
- // (`text_query`), or is not the last term in the text input, and
- // therefore the empty operand represents "general chat".
- //
- // (2) The user has selected a topic operator, and thus has
- // exactly `topic:` or `-topic:` written out, and it's appropriate
- // to suggest the "general chat" operand.
- //
- // (3) We're suggesting `topic` as a potential operator to add, say
- // if the user has typed `-to` so far. For that case, we want to
- // suggest adding a topic operator, but the user hasn't done anything
- // that would suggest we should further complete "general chat" as an
- // operand for that topic operator.
- if (
- // case 1
- text_query === "" ||
- index < search_terms.length - 1 ||
- // case 2
- text_query.trimEnd().endsWith("topic:")
- ) {
- // We want to show a combined pill for the case
- // where the preceding operator is a `channel`.
- const combined_channel_topic_pill_render_data =
- maybe_generate_combined_channel_topic_pill(
- index,
- search_terms,
- search_pill,
- );
- if (combined_channel_topic_pill_render_data) {
- redundant_channel_pill_index = index - 1;
- return combined_channel_topic_pill_render_data;
- }
-
- return {
- ...search_pill,
- is_empty_string_topic: true,
- sign: search_pill.negated ? "-" : "",
- topic_display_name: util.get_final_topic_display_name(""),
- };
- }
+ // There are three variants of an empty operand:
+ //
+ // (1) This is an already formed pill, i.e. not in the text input
+ // (`text_query`), or is not the last term in the text input, and
+ // therefore the empty operand represents "general chat".
+ //
+ // (2) The user has selected a topic operator, and thus has
+ // exactly `topic:` or `-topic:` written out, and it's appropriate
+ // to suggest the "general chat" operand.
+ //
+ // (3) We're suggesting `topic` as a potential operator to add, say
+ // if the user has typed `-to` so far. For that case, we want to
+ // suggest adding a topic operator, but the user hasn't done anything
+ // that would suggest we should further complete "general chat" as an
+ // operand for that topic operator.
+ if (
+ search_pill.operand === "" &&
+ // not case 1
+ text_query !== "" &&
+ index === search_terms.length - 1 &&
+ // not case 2
+ !text_query.trimEnd().endsWith("topic:")
+ ) {
// case 3
return {
...search_pill,
@@ -272,14 +252,23 @@ export function generate_pills_html(suggestion: Suggestion, text_query: string):
};
}
- // Try generating a combined channel topic pill for
- // non-empty operands.
+ // We want to show a combined pill for the case
+ // where the preceding operator is a `channel`.
const combined_channel_topic_pill_render_data =
maybe_generate_combined_channel_topic_pill(index, search_terms, search_pill);
if (combined_channel_topic_pill_render_data) {
redundant_channel_pill_index = index - 1;
return combined_channel_topic_pill_render_data;
}
+
+ if (search_pill.operand === "") {
+ return {
+ ...search_pill,
+ is_empty_string_topic: true,
+ sign: search_pill.negated ? "-" : "",
+ topic_display_name: util.get_final_topic_display_name(""),
+ };
+ }
break;
}
case "search": {