mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:17:34 +00:00
LibGUI: Insert first displayed emoji on return
This enables users to insert emojis without using the mouse by searching for it in the EmojiInputDialog and then hitting return.
This commit is contained in:
parent
178f0b9971
commit
e5a9f030f2
2 changed files with 25 additions and 3 deletions
|
@ -153,6 +153,10 @@ EmojiInputDialog::EmojiInputDialog(Window* parent_window)
|
|||
m_search_box->on_change = [this]() {
|
||||
update_displayed_emoji();
|
||||
};
|
||||
|
||||
m_search_box->on_return_pressed = [this]() {
|
||||
select_first_displayed_emoji();
|
||||
};
|
||||
}
|
||||
|
||||
auto EmojiInputDialog::supported_emoji() -> Vector<Emoji>
|
||||
|
@ -182,6 +186,7 @@ auto EmojiInputDialog::supported_emoji() -> Vector<Emoji>
|
|||
builder.append_code_point(*code_point);
|
||||
code_points.append(*code_point);
|
||||
});
|
||||
auto text = builder.to_string();
|
||||
|
||||
auto emoji = Unicode::find_emoji_for_code_points(code_points);
|
||||
if (!emoji.has_value()) {
|
||||
|
@ -193,7 +198,7 @@ auto EmojiInputDialog::supported_emoji() -> Vector<Emoji>
|
|||
auto button = EmojiButton::construct(move(code_points));
|
||||
button->set_fixed_size(button_size, button_size);
|
||||
button->set_button_style(Gfx::ButtonStyle::Coolbar);
|
||||
button->on_click = [this, text = builder.to_string()](auto) {
|
||||
button->on_click = [this, text](auto) {
|
||||
m_selected_emoji_text = move(text);
|
||||
done(ExecResult::OK);
|
||||
};
|
||||
|
@ -201,7 +206,7 @@ auto EmojiInputDialog::supported_emoji() -> Vector<Emoji>
|
|||
if (!emoji->name.is_empty())
|
||||
button->set_tooltip(emoji->name);
|
||||
|
||||
emojis.empend(move(button), emoji.release_value());
|
||||
emojis.empend(move(button), emoji.release_value(), move(text));
|
||||
}
|
||||
|
||||
quick_sort(emojis, [](auto const& lhs, auto const& rhs) {
|
||||
|
@ -217,6 +222,7 @@ void EmojiInputDialog::update_displayed_emoji()
|
|||
m_emojis_widget->set_updates_enabled(false);
|
||||
|
||||
m_emojis_widget->remove_all_children();
|
||||
m_first_displayed_emoji = nullptr;
|
||||
|
||||
constexpr size_t columns = 18;
|
||||
size_t rows = ceil_div(m_emojis.size(), columns);
|
||||
|
@ -247,13 +253,26 @@ void EmojiInputDialog::update_displayed_emoji()
|
|||
found_match = result.score > 0;
|
||||
}
|
||||
|
||||
if (found_match)
|
||||
if (found_match) {
|
||||
horizontal_container.add_child(*emoji.button);
|
||||
|
||||
if (m_first_displayed_emoji == nullptr)
|
||||
m_first_displayed_emoji = &emoji;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EmojiInputDialog::select_first_displayed_emoji()
|
||||
{
|
||||
if (m_first_displayed_emoji == nullptr)
|
||||
return;
|
||||
|
||||
m_selected_emoji_text = m_first_displayed_emoji->text;
|
||||
done(ExecResult::OK);
|
||||
}
|
||||
|
||||
void EmojiInputDialog::event(Core::Event& event)
|
||||
{
|
||||
if (event.type() == Event::KeyDown) {
|
||||
|
|
|
@ -19,6 +19,7 @@ class EmojiInputDialog final : public Dialog {
|
|||
struct Emoji {
|
||||
RefPtr<Button> button;
|
||||
Unicode::Emoji emoji;
|
||||
String text;
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -30,6 +31,7 @@ private:
|
|||
|
||||
Vector<Emoji> supported_emoji();
|
||||
void update_displayed_emoji();
|
||||
void select_first_displayed_emoji();
|
||||
|
||||
OwnPtr<ActionGroup> m_category_action_group;
|
||||
Optional<Unicode::EmojiGroup> m_selected_category;
|
||||
|
@ -38,6 +40,7 @@ private:
|
|||
RefPtr<Toolbar> m_toolbar;
|
||||
RefPtr<Widget> m_emojis_widget;
|
||||
Vector<Emoji> m_emojis;
|
||||
Emoji const* m_first_displayed_emoji { nullptr };
|
||||
String m_selected_emoji_text;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue