Emoji: Drop the shortname field from emoji.data

Match the name for Emoji completion, and display
it too. 'man worker' looks a lot more natural in
the UI than ':man_worker:'.
This commit is contained in:
Matthias Clasen 2020-04-15 01:19:09 -04:00
parent 1d9d5fcf39
commit 7ef5921022
5 changed files with 18 additions and 23 deletions

View File

@ -24,8 +24,6 @@
* sequence contains a 0, it marks the point * sequence contains a 0, it marks the point
* where skin tone modifiers should be inserted * where skin tone modifiers should be inserted
* s - name, e.g. "man worker" * s - name, e.g. "man worker"
* s - shortname, for completion. This includes
* colons to mark the ends, e.g. ":guardsman:"
* as - keywords, e.g. "man", "worker" * as - keywords, e.g. "man", "worker"
*/ */
#include <json-glib/json-glib.h> #include <json-glib/json-glib.h>
@ -127,7 +125,7 @@ main (int argc, char *argv[])
array = json_node_get_array (root); array = json_node_get_array (root);
length = json_array_get_length (array); length = json_array_get_length (array);
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(aussas)")); g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ausas)"));
i = 0; i = 0;
while (i < length) while (i < length)
{ {
@ -136,7 +134,6 @@ main (int argc, char *argv[])
GVariantBuilder b1; GVariantBuilder b1;
GVariantBuilder b2; GVariantBuilder b2;
const char *name; const char *name;
const char *shortname;
char *code; char *code;
int j, k; int j, k;
gboolean skip; gboolean skip;
@ -187,7 +184,6 @@ main (int argc, char *argv[])
obj2 = g_hash_table_lookup (names, name_key->str); obj2 = g_hash_table_lookup (names, name_key->str);
if (obj2) if (obj2)
{ {
shortname = json_object_get_string_member (obj2, "shortname");
kw = json_object_get_array_member (obj2, "keywords"); kw = json_object_get_array_member (obj2, "keywords");
for (k = 0; k < json_array_get_length (kw); k++) for (k = 0; k < json_array_get_length (kw); k++)
{ {
@ -209,12 +205,10 @@ main (int argc, char *argv[])
g_strfreev (ascii); g_strfreev (ascii);
} }
} }
else
shortname = "";
g_strfreev (name_tokens); g_strfreev (name_tokens);
g_variant_builder_add (&builder, "(aussas)", &b1, name, shortname, &b2); g_variant_builder_add (&builder, "(ausas)", &b1, name, &b2);
} }
v = g_variant_builder_end (&builder); v = g_variant_builder_end (&builder);

Binary file not shown.

View File

@ -337,8 +337,8 @@ add_recent_item (GtkEmojiChooser *chooser,
g_variant_ref (item); g_variant_ref (item);
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a((aussas)u)")); g_variant_builder_init (&builder, G_VARIANT_TYPE ("a((ausas)u)"));
g_variant_builder_add (&builder, "(@(aussas)u)", item, modifier); g_variant_builder_add (&builder, "(@(ausas)u)", item, modifier);
children = NULL; children = NULL;
for (child = gtk_widget_get_last_child (chooser->recent.box); for (child = gtk_widget_get_last_child (chooser->recent.box);
@ -363,7 +363,7 @@ add_recent_item (GtkEmojiChooser *chooser,
continue; continue;
} }
g_variant_builder_add (&builder, "(@(aussas)u)", item2, modifier2); g_variant_builder_add (&builder, "(@(ausas)u)", item2, modifier2);
} }
g_list_free (children); g_list_free (children);
@ -603,7 +603,7 @@ populate_emoji_chooser (gpointer data)
if (!chooser->data) if (!chooser->data)
{ {
GBytes *bytes = g_resources_lookup_data ("/org/gtk/libgtk/emoji/emoji.data", 0, NULL); GBytes *bytes = g_resources_lookup_data ("/org/gtk/libgtk/emoji/emoji.data", 0, NULL);
chooser->data = g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE ("a(aussas)"), bytes, TRUE)); chooser->data = g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE ("a(ausas)"), bytes, TRUE));
g_bytes_unref (bytes); g_bytes_unref (bytes);
} }
@ -765,7 +765,7 @@ filter_func (GtkFlowBoxChild *child,
g_variant_get_child (emoji_data, 1, "&s", &name); g_variant_get_child (emoji_data, 1, "&s", &name);
name_tokens = g_str_tokenize_and_fold (name, "en", NULL); name_tokens = g_str_tokenize_and_fold (name, "en", NULL);
g_variant_get_child (emoji_data, 3, "^a&s", &keywords); g_variant_get_child (emoji_data, 2, "^a&s", &keywords);
res = match_tokens ((const char **)term_tokens, (const char **)name_tokens) || res = match_tokens ((const char **)term_tokens, (const char **)name_tokens) ||
match_tokens ((const char **)term_tokens, keywords); match_tokens ((const char **)term_tokens, keywords);

View File

@ -115,7 +115,7 @@ next:
break; break;
} }
} }
while (g_unichar_isalnum (g_utf8_get_char (p)) || *p == '_'); while (g_unichar_isalnum (g_utf8_get_char (p)) || *p == '_' || *p == ' ');
if (found_candidate) if (found_candidate)
n_matches = populate_completion (completion, p, 0); n_matches = populate_completion (completion, p, 0);
@ -488,7 +488,7 @@ add_emoji (GtkWidget *list,
GtkWidget *box; GtkWidget *box;
PangoAttrList *attrs; PangoAttrList *attrs;
char text[64]; char text[64];
const char *shortname; const char *name;
GtkWidget *stack; GtkWidget *stack;
gunichar modifier; gunichar modifier;
@ -515,8 +515,8 @@ add_emoji (GtkWidget *list,
gtk_box_append (GTK_BOX (box), stack); gtk_box_append (GTK_BOX (box), stack);
g_object_set_data (G_OBJECT (child), "stack", stack); g_object_set_data (G_OBJECT (child), "stack", stack);
g_variant_get_child (emoji_data, 2, "&s", &shortname); g_variant_get_child (emoji_data, 1, "&s", &name);
label = gtk_label_new (shortname); label = gtk_label_new (name);
gtk_label_set_xalign (GTK_LABEL (label), 0); gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_stack_add_named (GTK_STACK (stack), label, "text"); gtk_stack_add_named (GTK_STACK (stack), label, "text");
@ -572,10 +572,11 @@ populate_completion (GtkEmojiCompletion *completion,
g_variant_iter_init (&iter, completion->data); g_variant_iter_init (&iter, completion->data);
while ((item = g_variant_iter_next_value (&iter))) while ((item = g_variant_iter_next_value (&iter)))
{ {
const char *shortname; const char *name;
g_variant_get_child (item, 2, "&s", &shortname); g_variant_get_child (item, 1, "&s", &name);
if (g_str_has_prefix (shortname, text))
if (g_str_has_prefix (name, text + 1))
{ {
n_matches++; n_matches++;
@ -623,7 +624,7 @@ gtk_emoji_completion_init (GtkEmojiCompletion *completion)
gtk_widget_init_template (GTK_WIDGET (completion)); gtk_widget_init_template (GTK_WIDGET (completion));
bytes = g_resources_lookup_data ("/org/gtk/libgtk/emoji/emoji.data", 0, NULL); bytes = g_resources_lookup_data ("/org/gtk/libgtk/emoji/emoji.data", 0, NULL);
completion->data = g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE ("a(auss)"), bytes, TRUE)); completion->data = g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE ("a(ausas)"), bytes, TRUE));
g_bytes_unref (bytes); g_bytes_unref (bytes);

View File

@ -2,12 +2,12 @@
<schemalist> <schemalist>
<schema id='org.gtk.gtk4.Settings.EmojiChooser' path='/org/gtk/gtk4/settings/emoji-chooser/'> <schema id='org.gtk.gtk4.Settings.EmojiChooser' path='/org/gtk/gtk4/settings/emoji-chooser/'>
<key name='recent-emoji' type='a((aussas)u)'> <key name='recent-emoji' type='a((ausas)u)'>
<default>[]</default> <default>[]</default>
<summary>Recently used Emoji</summary> <summary>Recently used Emoji</summary>
<description> <description>
An array of Emoji definitions to show in the Emoji chooser. Each Emoji is An array of Emoji definitions to show in the Emoji chooser. Each Emoji is
specified as an array of codepoints, name, shortname and keywords. The extra specified as an array of codepoints, name and keywords. The extra
integer after this pair is the code of the Fitzpatrick modifier to use in integer after this pair is the code of the Fitzpatrick modifier to use in
place of a 0 in the codepoint array. place of a 0 in the codepoint array.
</description> </description>