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.

typeahead: Fix stream+topic completions for empty query.

ryanreh99b38cbc8f34d9
diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.js
index e3cdba609a5..b5be5ba9e61 100644
--- a/frontend_tests/node_tests/composebox_typeahead.js
+++ b/frontend_tests/node_tests/composebox_typeahead.js
@@ -481,6 +481,21 @@ run_test("content_typeahead_selected", () => {
expected_value = "#**Sweden** ";
assert.equal(actual_value, expected_value);
+ // topic_list
+ fake_this.completing = "topic_list";
+
+ fake_this.query = "Hello #**Sweden>test";
+ fake_this.token = "test";
+ actual_value = ct.content_typeahead_selected.call(fake_this, "testing");
+ expected_value = "Hello #**Sweden>testing** ";
+ assert.equal(actual_value, expected_value);
+
+ fake_this.query = "Hello #**Sweden>";
+ fake_this.token = "";
+ actual_value = ct.content_typeahead_selected.call(fake_this, "testing");
+ expected_value = "Hello #**Sweden>testing** ";
+ assert.equal(actual_value, expected_value);
+
// syntax
fake_this.completing = "syntax";
diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js
index 23cd5446aaf..23713139d9c 100644
--- a/static/js/composebox_typeahead.js
+++ b/static/js/composebox_typeahead.js
@@ -853,8 +853,9 @@ exports.content_typeahead_selected = function (item, event) {
}
} else if (this.completing === "topic_list") {
// Stream + topic mention typeahead; close the stream+topic mention syntax
- // with the topic and the final **.
- const start = -this.token.length;
+ // with the topic and the final **. Note that this.token.length can be 0
+ // if we are completing from `**streamname>`.
+ const start = beginning.length - this.token.length;
beginning = beginning.slice(0, start) + item + "** ";
} else if (this.completing === "time_jump") {
let timestring = beginning.slice(Math.max(0, beginning.lastIndexOf("<time:")));