From 0d9b77c8b7d34515763fbf6dd4ee742785be485d Mon Sep 17 00:00:00 2001 From: Cory Lynch Date: Thu, 20 Apr 2017 00:28:18 -0400 Subject: [PATCH] composebox_typeahead.js: Add typeahead cancelling for '# '. If somebody types '# ', then close the typeahead dialog and don't autocomplete. Relevant node tests were also added. Fixes #4505. --- frontend_tests/node_tests/composebox_typeahead.js | 2 ++ static/js/composebox_typeahead.js | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.js index 10f95da62c..7d9df5d7de 100644 --- a/frontend_tests/node_tests/composebox_typeahead.js +++ b/frontend_tests/node_tests/composebox_typeahead.js @@ -59,6 +59,8 @@ global.people.add({ assert_typeahead_equals("test @", false); assert_typeahead_equals("test no@o", false); assert_typeahead_equals("test :-P", false); + assert_typeahead_equals("test # a", false); + assert_typeahead_equals("test #", false); var all_items = [ { diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js index 5d248fea87..e041daf193 100644 --- a/static/js/composebox_typeahead.js +++ b/static/js/composebox_typeahead.js @@ -289,6 +289,11 @@ exports.compose_content_begins_typeahead = function (query) { return false; } + // Don't autocomplete if there is a space following a '#' + if (current_token[0] === " ") { + return false; + } + this.completing = 'stream'; this.token = current_token.substring(current_token.indexOf("#")+1); return stream_data.subscribed_subs();