typeahead: Show the time typeahead irrespective of text before syntax.

Uptil now, on typing "<time" after some other autocompleteable token
like a mention or emoji, the timezone aware time typeahead would not
get triggered since the time syntax was checked after the earlier syntax
had been mistakenly used to (wrongly) tokenize the precursor text.

Now the code has been fixed to detect the time syntax the same way as
the rest: checking each character in the precursor text from end to
start, and tokenize it correctly.

Fixes: #23998.
This commit is contained in:
N-Shar-ma 2023-01-17 19:22:09 +05:30 committed by Tim Abbott
parent ba443cac03
commit 25eff08324
2 changed files with 6 additions and 5 deletions

View File

@ -1274,6 +1274,7 @@ test("begins_typeahead", ({override, override_rewire}) => {
assert_typeahead_equals("@zulip :ta", emoji_list);
assert_stream_list(":tada: #foo");
assert_typeahead_equals("#foo\n~~~py", lang_list);
assert_typeahead_equals(":tada: <time:", ["translated: Mention a time-zone-aware time"]);
assert_typeahead_equals("@", all_mentions);
assert_typeahead_equals("@_", people_only);

View File

@ -314,6 +314,11 @@ export function tokenize_compose_str(s) {
return s.slice(i);
}
break;
case "<":
if (s.indexOf("<time", i) === i) {
return s.slice(i);
}
break;
case ">":
// topic_jump
//
@ -333,11 +338,6 @@ export function tokenize_compose_str(s) {
}
}
const timestamp_index = s.indexOf("<time");
if (timestamp_index >= 0) {
return s.slice(timestamp_index);
}
return "";
}