diff --git a/README.md b/README.md index 642bffb..34211b3 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,8 @@ Multi-platform features: ## TO-DO * [ ] “Recently used” group -* [ ] Better emoji look-ups +* [x] Better emoji look-ups + * Uses shortcodes * [x] Emojis should be displayed in a grid * [ ] Polish design * [ ] Add a *tooltip* to see the name of the emojis diff --git a/src/emoji.rs b/src/emoji.rs index cfb0332..98cd68e 100644 --- a/src/emoji.rs +++ b/src/emoji.rs @@ -16,6 +16,10 @@ impl EmojiWrapper { self.0.skin_tones().map(|x| x.map(EmojiWrapper)) } + pub fn shortcodes(&self) -> impl Iterator { + self.0.shortcodes() + } + pub fn skin_tone(&self) -> Option { self.0.skin_tone().and_then(EmojiWrapper::skin_tone_idx) } diff --git a/src/emoji_model.rs b/src/emoji_model.rs index c4a3fd6..652664c 100644 --- a/src/emoji_model.rs +++ b/src/emoji_model.rs @@ -4,7 +4,7 @@ use crate::{ emoji::{EmojiGroupWrapper, EmojiWrapper}, EmojiGroupModel, EmojiModel, EmojiSkinToneModel, }; -use slint::{Model, ModelNotify, ModelRc, VecModel}; +use slint::{Model, ModelNotify, ModelRc, SharedString, VecModel}; impl From for EmojiModel { fn from(e: EmojiWrapper) -> EmojiModel { @@ -17,6 +17,7 @@ impl From for EmojiModel { name: e.name().into(), code: e.code().into(), image: image.unwrap_or_default(), + shortcodes: ModelRc::new(VecModel::from(e.shortcodes().map(|x| SharedString::from(x)).collect::>())), skin_tones: ModelRc::new(VecModel::from(match e.skin_tones() { Some(iterator) => iterator .map(EmojiSkinToneModel::try_from) @@ -71,7 +72,7 @@ impl VecEmojiListModel { fn filter_down(&self, filter: String) { let filter = filter.to_lowercase(); let mut emojis = self.vec.borrow_mut(); - emojis.retain(|x| x.name.contains(&filter)); + VecEmojiListModel::retain_search(&mut emojis, &filter); self.filter.replace(filter); self.notify.reset() } @@ -79,11 +80,17 @@ impl VecEmojiListModel { pub fn filter_up(&self, filter: String) { let filter = filter.to_lowercase(); let mut emojis = self.initial.borrow().clone(); - emojis.retain(|x| x.name.to_lowercase().contains(&filter)); + VecEmojiListModel::retain_search(&mut emojis, &filter); self.filter.replace(filter); self.vec.replace(emojis); self.notify.reset() } + + fn retain_search(v: &mut Vec, filter: &str) { + v.retain(|x| { + x.name.contains(&filter) || x.shortcodes.iter().any(|s| s.contains(&filter)) + }) + } } impl Model for VecEmojiListModel { diff --git a/ui/emoji-model.slint b/ui/emoji-model.slint index 2603ea9..44b3cbd 100644 --- a/ui/emoji-model.slint +++ b/ui/emoji-model.slint @@ -8,6 +8,7 @@ export struct EmojiModel { name: string, code: string, image: image, + shortcodes: [string], skin-tones: [EmojiSkinToneModel] }