hadley / emo

Easily insert emoji into R and RMarkdown
416 stars 53 forks source link

make `ji_completion()` compatible with spaces #62

Open matiasandina opened 3 years ago

matiasandina commented 3 years ago

Right now, ji_completion fails when the query has spaces.

 ji_completion("water polo")
  :  

I think this should be the desired behavior

> ji_completion(str_replace_all("water polo", " ", "_"))
🤽  :  person_playing_water_polo
🤽🏻  :  person_playing_water_polo_light_skin_tone
🤽🏼  :  person_playing_water_polo_medium_light_skin_tone
...

I think it could be a good idea to switch from this

{
    matches <- emo::ji_name[str_detect(names(emo::ji_name), token)]
    matches <- matches[!duplicated(matches)]
    structure(matches, class = c("emoji_completion"))
}

To this version, which handles spaces.

  function (token) 
  {
    token <- str_replace_all(token, pattern = " ", replacement = "_")
    matches <- emo::ji_name[str_detect(names(emo::ji_name), token)]
    matches <- matches[!duplicated(matches)]
   structure(matches, class = c("emoji_completion"))
  }

It's true that a user might add other characters that might mess up completion and are not handled by the function, but spaces is probably the most common, and this is an easy fix.