chat: fix emoji completions when word consists of emojis (#9107)

https://github.com/zed-industries/zed/assets/53836821/f4b31c47-d306-43f5-b971-0969f64a48f9

Fix for #9096 @JosephTLyons 

Release Notes:
- Fixed emoji completion not showing up when word contains only emojis
(#9096)
This commit is contained in:
Bennet Bo Fenner 2024-03-11 16:08:18 +01:00 committed by GitHub
parent eb5e18c66d
commit a8fa1f7363
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 101 additions and 9 deletions

View file

@ -407,6 +407,23 @@ impl MessageEditor {
if next_char.is_none() || next_char.unwrap().is_whitespace() {
return Some(query.chars().rev().collect::<String>());
}
// If the previous character is not a whitespace, we are in the middle of a word
// and we only want to complete the shortcode if the word is made up of other emojis
let mut containing_word = String::new();
for ch in buffer
.reversed_chars_at(end_offset - query.len() - 1)
.take(100)
{
if ch.is_whitespace() {
break;
}
containing_word.push(ch);
}
let containing_word = containing_word.chars().rev().collect::<String>();
if util::word_consists_of_emojis(containing_word.as_str()) {
return Some(query.chars().rev().collect::<String>());
}
break;
}
if ch.is_whitespace() || !ch.is_ascii() {