mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-17 01:10:28 +03:00
LibGUI: Display emoji in the EmojiInputDialog in Unicode display order
This commit is contained in:
parent
c2148c7dde
commit
273045d40e
Notes:
sideshowbarker
2024-07-17 07:20:32 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/273045d40e Pull-request: https://github.com/SerenityOS/serenity/pull/15159 Reviewed-by: https://github.com/linusg ✅
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/QuickSort.h>
|
||||
#include <AK/ScopeGuard.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Utf32View.h>
|
||||
@ -70,7 +71,7 @@ auto EmojiInputDialog::supported_emoji() -> Vector<Emoji>
|
||||
continue;
|
||||
|
||||
u32 code_point = strtoul(basename.to_string().characters() + 2, nullptr, 16);
|
||||
auto name = Unicode::code_point_display_name(code_point);
|
||||
auto emoji = Unicode::find_emoji_for_code_points({ code_point });
|
||||
|
||||
// FIXME: Also emit U+FE0F for single code point emojis, currently
|
||||
// they get shown as text glyphs if available.
|
||||
@ -90,12 +91,22 @@ auto EmojiInputDialog::supported_emoji() -> Vector<Emoji>
|
||||
done(ExecResult::OK);
|
||||
};
|
||||
|
||||
if (name.has_value())
|
||||
button->set_tooltip(name->to_titlecase());
|
||||
if (emoji.has_value())
|
||||
button->set_tooltip(emoji->name);
|
||||
|
||||
code_points.empend(code_point, move(name), move(button));
|
||||
code_points.empend(code_point, move(button), move(emoji));
|
||||
}
|
||||
|
||||
quick_sort(code_points, [](auto const& lhs, auto const& rhs) {
|
||||
if (lhs.emoji.has_value() && rhs.emoji.has_value())
|
||||
return lhs.emoji->display_order < rhs.emoji->display_order;
|
||||
if (lhs.emoji.has_value())
|
||||
return true;
|
||||
if (rhs.emoji.has_value())
|
||||
return false;
|
||||
return lhs.code_point < rhs.code_point;
|
||||
});
|
||||
|
||||
return code_points;
|
||||
}
|
||||
|
||||
@ -123,8 +134,8 @@ void EmojiInputDialog::update_displayed_emoji()
|
||||
while (!found_match && (index < m_emojis.size())) {
|
||||
auto& emoji = m_emojis[index++];
|
||||
|
||||
if (emoji.name.has_value())
|
||||
found_match = emoji.name->contains(m_search_box->text(), CaseSensitivity::CaseInsensitive);
|
||||
if (emoji.emoji.has_value())
|
||||
found_match = emoji.emoji->name.contains(m_search_box->text(), CaseSensitivity::CaseInsensitive);
|
||||
else
|
||||
found_match = m_search_box->text().is_empty();
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <LibGUI/Dialog.h>
|
||||
#include <LibUnicode/Emoji.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
@ -15,8 +16,8 @@ class EmojiInputDialog final : public Dialog {
|
||||
|
||||
struct Emoji {
|
||||
u32 code_point { 0 };
|
||||
Optional<String> name;
|
||||
RefPtr<Button> button;
|
||||
Optional<Unicode::Emoji> emoji;
|
||||
};
|
||||
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user