Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
search_suggestion: Omit operand in pill for autocomplete suggestion.
Pratik Chandade18ff348c8d
diff --git a/web/src/search.ts b/web/src/search.tsindex 71201516f8b..1a95f6014b7 100644--- a/web/src/search.ts+++ b/web/src/search.ts@@ -191,10 +191,10 @@ export function initialize(opts: {on_narrow_search: OnNarrowSearch}): void {helpOnEmptyStrings: true,stopAdvance: true,requireHighlight: false,- item_html(item: string): string {+ item_html(item: string, query: string): string {const obj = search_map.get(item);assert(obj !== undefined);- return search_pill.generate_pills_html(obj);+ return search_pill.generate_pills_html(obj, query);},// When the user starts typing new search operands,// we want to highlight the first typeahead row by defaultdiff --git a/web/src/search_pill.ts b/web/src/search_pill.tsindex dfa1f8ad9ff..34778759269 100644--- a/web/src/search_pill.ts+++ b/web/src/search_pill.ts@@ -121,7 +121,7 @@ function on_pill_exit(// pill. We can probably simplify things by separating out a function// that generates `description_html` from the information in a single// search pill, and remove `description_html` from the `Suggestion` type.-export function generate_pills_html(suggestion: Suggestion): string {+export function generate_pills_html(suggestion: Suggestion, query: string): string {const search_terms = Filter.parse(suggestion.search_string);const pill_render_data = search_terms.map((term, index) => {@@ -136,11 +136,32 @@ export function generate_pills_html(suggestion: Suggestion): string {};if (search_pill.operator === "topic" && search_pill.operand === "") {+ // There are two variants of this suggestion state: One is the user+ // has selected a topic operator and operator, and and thus has+ // exactly `topic:` or `-topic:` written out, and it's be+ // appropriate to suggest the "general chat" value.+ //+ // The other variant is where 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 value for that topic operator.+ //+ // We can simply differentiate these cases by checking if `:` is+ // present in the query. See `set_search_bar_contents` for more+ // context.+ if (query.includes(":")) {+ return {+ ...search_pill,+ is_empty_string_topic: true,+ sign: search_pill.negated ? "-" : "",+ topic_display_name: util.get_final_topic_display_name(""),+ };+ }return {...search_pill,is_empty_string_topic: true,sign: search_pill.negated ? "-" : "",- topic_display_name: util.get_final_topic_display_name(""),};}if (search_pill.operator === "search") {diff --git a/web/templates/input_pill.hbs b/web/templates/input_pill.hbsindex 983778c0310..5f3f96d8f66 100644--- a/web/templates/input_pill.hbs+++ b/web/templates/input_pill.hbs@@ -18,7 +18,7 @@{{~/if~}}{{/if}}{{#if is_empty_string_topic}}- {{sign}}topic: <span class="empty-topic-display">{{topic_display_name}}</span>+ {{sign}}topic:{{#if topic_display_name}}<span class="empty-topic-display"> {{topic_display_name}}</span>{{/if}}{{else}}{{ display_value }}{{/if}}