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:
parent
eb5e18c66d
commit
a8fa1f7363
6 changed files with 101 additions and 9 deletions
|
@ -28,6 +28,7 @@ lazy_static.workspace = true
|
|||
log.workspace = true
|
||||
parking_lot.workspace = true
|
||||
rand.workspace = true
|
||||
regex.workspace = true
|
||||
rust-embed.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
|
|
|
@ -524,6 +524,22 @@ impl<'a> PartialOrd for NumericPrefixWithSuffix<'a> {
|
|||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
lazy_static! {
|
||||
static ref EMOJI_REGEX: regex::Regex = regex::Regex::new("(\\p{Emoji}|\u{200D})").unwrap();
|
||||
}
|
||||
|
||||
/// Returns true if the given string consists of emojis only.
|
||||
/// E.g. "👨👩👧👧👋" will return true, but "👋!" will return false.
|
||||
pub fn word_consists_of_emojis(s: &str) -> bool {
|
||||
let mut prev_end = 0;
|
||||
for capture in EMOJI_REGEX.find_iter(s) {
|
||||
if capture.start() != prev_end {
|
||||
return false;
|
||||
}
|
||||
prev_end = capture.end();
|
||||
}
|
||||
prev_end == s.len()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
@ -583,4 +599,21 @@ mod tests {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_word_consists_of_emojis() {
|
||||
let words_to_test = vec![
|
||||
("👨👩👧👧👋🥒", true),
|
||||
("👋", true),
|
||||
("!👋", false),
|
||||
("👋!", false),
|
||||
("👋 ", false),
|
||||
(" 👋", false),
|
||||
("Test", false),
|
||||
];
|
||||
|
||||
for (text, expected_result) in words_to_test {
|
||||
assert_eq!(word_consists_of_emojis(text), expected_result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue