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.

composebox_typeahead: Fix Escape resolution of partial topic links.

Shubham Padia00a1df281e58
diff --git a/web/src/composebox_typeahead.ts b/web/src/composebox_typeahead.ts
index cdef3d3fd68..5f013f62ce9 100644
--- a/web/src/composebox_typeahead.ts
+++ b/web/src/composebox_typeahead.ts
@@ -1482,11 +1482,12 @@ export function content_typeahead_selected(
}
case "topic_list": {
// If we use "Escape" we would want `#**design>this is a design topic` to be
- // resolved to `#**design** this is a design topic`
+ // resolved to `#**design** this is a design topic`, i.e. a link to the
+ // channel followed by the partially typed topic as plain text.
if (event?.key === "Escape") {
- const topic_start_index = beginning.lastIndexOf(">");
- const topic = beginning.slice(topic_start_index + 1);
- beginning = beginning.slice(0, topic_start_index) + "** " + topic;
+ const syntax_start_index = beginning.lastIndexOf(item.used_syntax_prefix);
+ const stream_link = topic_link_util.get_stream_link_syntax(item.stream_data.name);
+ beginning = beginning.slice(0, syntax_start_index) + stream_link + " " + token;
break;
}
diff --git a/web/tests/composebox_typeahead.test.cjs b/web/tests/composebox_typeahead.test.cjs
index a23560412df..01f09a51cb0 100644
--- a/web/tests/composebox_typeahead.test.cjs
+++ b/web/tests/composebox_typeahead.test.cjs
@@ -1450,6 +1450,50 @@ test("content_typeahead_selected", ({override}) => {
expected_value = "Hello #**Sweden** plan";
assert.equal(actual_value, expected_value);
+ // Escape with the shortcut syntax for the channel being composed to.
+ compose_state.set_stream_id(sweden_stream.stream_id);
+ query = "Hello #>plan";
+ ct.get_or_set_token_for_testing("plan");
+ actual_value = ct.content_typeahead_selected(
+ {
+ topic: "planning",
+ topic_display_name: "planning",
+ type: "topic_list",
+ used_syntax_prefix: "#>",
+ is_channel_link: false,
+ stream_data: {
+ name: "Sweden",
+ },
+ },
+ query,
+ input_element,
+ {key: "Escape"},
+ );
+ expected_value = "Hello #**Sweden** plan";
+ assert.equal(actual_value, expected_value);
+
+ // Escape with the fallback markdown link syntax used for channel
+ // names that would produce broken `#**channel**` links.
+ query = "Hello [#A* Algorithm](#narrow/channel/6-A.2A-Algorithm)>fast";
+ ct.get_or_set_token_for_testing("fast");
+ actual_value = ct.content_typeahead_selected(
+ {
+ topic: "fast",
+ topic_display_name: "fast",
+ type: "topic_list",
+ used_syntax_prefix: "[#",
+ is_channel_link: false,
+ stream_data: {
+ name: "A* Algorithm",
+ },
+ },
+ query,
+ input_element,
+ {key: "Escape"},
+ );
+ expected_value = "Hello [#A* Algorithm](#narrow/channel/6-A.2A-Algorithm) fast";
+ assert.equal(actual_value, expected_value);
+
// syntax
ct.get_or_set_completing_for_tests("syntax");