Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typeahead: Don't stop midphrase matching when a second word is typed.
Greg Pricedc6e9df43abc
diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.jsindex 867cef67209..955374daf17 100644--- a/frontend_tests/node_tests/composebox_typeahead.js+++ b/frontend_tests/node_tests/composebox_typeahead.js@@ -1546,23 +1546,34 @@ test("typeahead_results", () => {{emoji_name: "japanese_post_office", emoji_code: "1f3e3"},]);assert_emoji_matches("notaemoji", []);+// Autocomplete user mentions by user name.assert_mentions_matches("cordelia", [cordelia]);assert_mentions_matches("cordelia, le", [cordelia]);assert_mentions_matches("cordelia, le ", []);+ assert_mentions_matches("moor", [othello]);+ assert_mentions_matches("moor ", [othello]);+ assert_mentions_matches("moor of", [othello]);+ assert_mentions_matches("moor of ven", [othello]);+ assert_mentions_matches("oor", [othello]);+ assert_mentions_matches("oor ", []);+ assert_mentions_matches("oor o", []);+ assert_mentions_matches("oor of venice", []);assert_mentions_matches("King ", [hamlet, lear]);assert_mentions_matches("King H", [hamlet]);assert_mentions_matches("King L", [lear]);assert_mentions_matches("delia lear", []);assert_mentions_matches("Mark Tw", [twin1, twin2]);+// Autocomplete user group mentions by group name.assert_mentions_matches("hamletchar", [hamletcharacters]);+// Autocomplete user group mentions by group descriptions.assert_mentions_matches("characters ", [hamletcharacters]);assert_mentions_matches("characters of ", [hamletcharacters]);assert_mentions_matches("characters o ", []);assert_mentions_matches("haracters of hamlet", []);- assert_mentions_matches("of hamlet", []);+ assert_mentions_matches("of hamlet", [hamletcharacters]);// Autocomplete by slash commands.assert_slash_matches("me", [me_slash]);diff --git a/frontend_tests/node_tests/typeahead.js b/frontend_tests/node_tests/typeahead.jsindex 0b7540cd222..8c94dc30099 100644--- a/frontend_tests/node_tests/typeahead.js+++ b/frontend_tests/node_tests/typeahead.js@@ -50,6 +50,12 @@ run_test("get_emoji_matcher: misc matches", () => {assert_emoji_matches("japanese post ", ["japanese_post_office"]);});+run_test("matches starting at non-first word, too", () => {+ assert_emoji_matches("ice_cream", ["ice_cream", "soft_ice_cream"]);+ assert_emoji_matches("blue_dia", ["large_blue_diamond", "small_blue_diamond"]);+ assert_emoji_matches("traffic_", ["horizontal_traffic_light", "traffic_light"]);+});+run_test("triage", () => {const alice = {name: "alice"};const alicia = {name: "Alicia"};diff --git a/static/shared/js/typeahead.js b/static/shared/js/typeahead.jsindex 50cb7f034c1..2c1fcb81636 100644--- a/static/shared/js/typeahead.js+++ b/static/shared/js/typeahead.js@@ -44,27 +44,10 @@ function query_matches_string(query, source_str, split_char) {}// If there is a separator character in the query, then we- // require a perfect prefix match (e.g. for 'ab cd ef',- // query needs to be e.g. 'ab c', not 'cd ef' or 'b cd- // ef', etc.).-- const queries = query.split(split_char);- const sources = source_str.split(split_char);- let i;-- for (i = 0; i < queries.length - 1; i += 1) {- if (sources[i] !== queries[i]) {- return false;- }- }-- // This block is effectively a final iteration of the last- // loop. What differs is that for the last word, a- // partial match at the beginning of the word is OK.- if (sources[i] === undefined) {- return false;- }- return sources[i].startsWith(queries[i]);+ // require the match to start at the start of a token.+ // (E.g. for 'ab cd ef', query could be 'ab c' or 'cd ef',+ // but not 'b cd ef'.)+ return source_str.startsWith(query) || source_str.includes(split_char + query);}// This function attempts to match a query with source's attributes.