Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
composebox_typeahead: Show empty-topic completion only on ">".
Shubham Padia4fa8b60cc34e
diff --git a/web/src/composebox_typeahead.ts b/web/src/composebox_typeahead.tsindex 73914043b92..14ce5a33994 100644--- a/web/src/composebox_typeahead.ts+++ b/web/src/composebox_typeahead.ts@@ -1223,14 +1223,31 @@ export function get_candidates(}// If we aren't composing to a channel, `sub` would be undefined.if (sub !== undefined) {- if (- is_complete_channel_link &&- stream_data.is_empty_topic_only_channel(sub.stream_id)- ) {- // This channel only allows the empty topic, so the- // complete channel link is the final form; don't offer- // topic completion.- return [];+ if (stream_data.is_empty_topic_only_channel(sub.stream_id)) {+ if (is_complete_channel_link) {+ // The complete channel link is the final form, so+ // don't open topic completion by default; the user+ // must press ">" to reach the empty topic.+ return [];+ }+ // The user asked for a topic with ">", but this channel+ // only allows the empty topic, so offer just that single+ // topic rather than offering or creating named ones.+ const empty_topic_suggestion: TopicSuggestion = {+ topic: "",+ topic_display_name: util.get_final_topic_display_name(""),+ is_empty_string_topic: true,+ type: "topic_list",+ is_channel_link: false,+ used_syntax_prefix,+ stream_data: {+ ...sub,+ type: "stream",+ rendered_description: "",+ },+ is_new_topic: false,+ };+ return [empty_topic_suggestion];}// We always show topic suggestions after the user types a stream, and let them// pick between just showing the stream (the first option, when nothing follows ">")diff --git a/web/tests/composebox_typeahead.test.cjs b/web/tests/composebox_typeahead.test.cjsindex d7e4e060eb4..98ebdf06fe8 100644--- a/web/tests/composebox_typeahead.test.cjs+++ b/web/tests/composebox_typeahead.test.cjs@@ -3047,6 +3047,27 @@ test("begins_typeahead", ({override, override_rewire}) => {// A channel that only allows the empty topic gets a complete channel// link with no topic completion offered.assert_typeahead_equals("#**Announce**", []);+ // Once the user presses ">", completion is offered to just that+ // single (empty) topic, and never to named ones.+ const announce_empty_topic_suggestion = [+ {+ topic: "",+ topic_display_name: get_final_topic_display_name(""),+ is_empty_string_topic: true,+ type: "topic_list",+ is_channel_link: false,+ used_syntax_prefix: "#**",+ stream_data: {+ ...stream_data.get_sub_by_name("Announce"),+ rendered_description: "",+ },+ is_new_topic: false,+ },+ ];+ assert_typeahead_equals("#**Announce>", announce_empty_topic_suggestion);+ // Text typed after ">" cannot create a named topic; only the empty+ // topic is still offered.+ assert_typeahead_equals("#**Announce>random", announce_empty_topic_suggestion);compose_ui.compose_textarea_typeahead = undefined;// time_jump