shared: Match literal emoji in typeahead.

This PR implements checking for a literal emoji match in emoji
typeaheads. In other words, if you paste or type panda face into an
emoji typeahead, panda face should be presented as an option to choose
from.

This behavior is currently present in the mobile app, adding it to
shared will enable both platforms to utilize this logic.
This commit is contained in:
Austin Riba 2022-04-04 15:54:19 -07:00 committed by Tim Abbott
parent 09860dc284
commit a8fd535955
2 changed files with 13 additions and 1 deletions

View File

@ -52,6 +52,8 @@ run_test("get_emoji_matcher", () => {
assert_matches("japanese_post_", [emoji_japanese_post_office]);
assert_matches("japanese post ", [emoji_japanese_post_office]);
assert_matches("🐼", [emoji_panda_face]);
});
run_test("triage", () => {

View File

@ -98,13 +98,23 @@ export function clean_query_lowercase(query) {
return query;
}
export const parse_unicode_emoji_code = (code) =>
code
.split("-")
.map((hex) => String.fromCodePoint(Number.parseInt(hex, 16)))
.join("");
export function get_emoji_matcher(query) {
// replaces spaces with underscores for emoji matching
query = query.replace(/ /g, "_");
query = clean_query_lowercase(query);
return function (emoji) {
return query_matches_source_attrs(query, emoji, ["emoji_name"], "_");
const matches_emoji_literal =
emoji.emoji_code && parse_unicode_emoji_code(emoji.emoji_code) === query;
return (
matches_emoji_literal || query_matches_source_attrs(query, emoji, ["emoji_name"], "_")
);
};
}