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
|
@ -2653,10 +2653,31 @@ impl Editor {
|
|||
let mut found_colon = false;
|
||||
for char in snapshot.reversed_chars_at(position).take(100) {
|
||||
// Found a possible emoji shortcode in the middle of the buffer
|
||||
if found_colon && char.is_whitespace() {
|
||||
chars.reverse();
|
||||
return Some(chars.iter().collect());
|
||||
if found_colon {
|
||||
if char.is_whitespace() {
|
||||
chars.reverse();
|
||||
return Some(chars.iter().collect());
|
||||
}
|
||||
// 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 snapshot
|
||||
.reversed_chars_at(position)
|
||||
.skip(chars.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()) {
|
||||
chars.reverse();
|
||||
return Some(chars.iter().collect());
|
||||
}
|
||||
}
|
||||
|
||||
if char.is_whitespace() || !char.is_ascii() {
|
||||
return None;
|
||||
}
|
||||
|
|
|
@ -5206,20 +5206,39 @@ async fn test_auto_replace_emoji_shortcode(cx: &mut gpui::TestAppContext) {
|
|||
editor.handle_input(":", cx);
|
||||
assert_eq!(editor.text(cx), "Hello 👋 😄".unindent());
|
||||
|
||||
editor.handle_input(":1:", cx);
|
||||
assert_eq!(editor.text(cx), "Hello 👋 😄:1:".unindent());
|
||||
// Ensure shortcode gets replaced when it is part of a word that only consists of emojis
|
||||
editor.handle_input(":wave", cx);
|
||||
assert_eq!(editor.text(cx), "Hello 👋 😄:wave".unindent());
|
||||
|
||||
editor.handle_input(":", cx);
|
||||
assert_eq!(editor.text(cx), "Hello 👋 😄👋".unindent());
|
||||
|
||||
editor.handle_input(":1", cx);
|
||||
assert_eq!(editor.text(cx), "Hello 👋 😄👋:1".unindent());
|
||||
|
||||
editor.handle_input(":", cx);
|
||||
assert_eq!(editor.text(cx), "Hello 👋 😄👋:1:".unindent());
|
||||
|
||||
// Ensure shortcode does not get replaced when it is part of a word
|
||||
editor.handle_input(" Test:wave:", cx);
|
||||
assert_eq!(editor.text(cx), "Hello 👋 😄:1: Test:wave:".unindent());
|
||||
editor.handle_input(" Test:wave", cx);
|
||||
assert_eq!(editor.text(cx), "Hello 👋 😄👋:1: Test:wave".unindent());
|
||||
|
||||
editor.handle_input(":", cx);
|
||||
assert_eq!(editor.text(cx), "Hello 👋 😄👋:1: Test:wave:".unindent());
|
||||
|
||||
editor.set_auto_replace_emoji_shortcode(false);
|
||||
|
||||
// Ensure shortcode does not get replaced when auto replace is off
|
||||
editor.handle_input(" :wave:", cx);
|
||||
editor.handle_input(" :wave", cx);
|
||||
assert_eq!(
|
||||
editor.text(cx),
|
||||
"Hello 👋 😄:1: Test:wave: :wave:".unindent()
|
||||
"Hello 👋 😄👋:1: Test:wave: :wave".unindent()
|
||||
);
|
||||
|
||||
editor.handle_input(":", cx);
|
||||
assert_eq!(
|
||||
editor.text(cx),
|
||||
"Hello 👋 😄👋:1: Test:wave: :wave:".unindent()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue