diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 8d18cf0c8a..587a61f9ce 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -2517,10 +2517,11 @@ gtk_label_set_markup_internal (GtkLabel *label, GError *error = NULL; PangoAttrList *attrs = NULL; gunichar accel_char = 0; - gchar *new_str; + gchar *str_for_display = NULL; + gchar *str_for_accel = NULL; GList *links = NULL; - if (!parse_uri_markup (label, str, &new_str, &links, &error)) + if (!parse_uri_markup (label, str, &str_for_display, &links, &error)) { g_warning ("Failed to set text from markup due to error parsing markup: %s", error->message); @@ -2528,6 +2529,8 @@ gtk_label_set_markup_internal (GtkLabel *label, return; } + str_for_accel = g_strdup (str_for_display); + if (links) { gtk_label_ensure_select_info (label); @@ -2555,31 +2558,51 @@ gtk_label_set_markup_internal (GtkLabel *label, gchar *pattern; guint key; - if (separate_uline_pattern (new_str, &key, &tmp, &pattern)) + if (separate_uline_pattern (str_for_display, &key, &tmp, &pattern)) { - g_free (new_str); - new_str = tmp; + g_free (str_for_display); + str_for_display = tmp; g_free (pattern); } } } - if (!pango_parse_markup (new_str, + /* Extract the text to display */ + if (!pango_parse_markup (str_for_display, -1, - with_uline ? '_' : 0, + 0, &attrs, &text, - with_uline ? &accel_char : NULL, + NULL, &error)) { g_warning ("Failed to set text from markup due to error parsing markup: %s", error->message); - g_free (new_str); + g_free (str_for_display); + g_free (str_for_accel); g_error_free (error); return; } - g_free (new_str); + /* Extract the accelerator character */ + if (with_uline && !pango_parse_markup (str_for_accel, + -1, + '_', + NULL, + NULL, + &accel_char, + &error)) + { + g_warning ("Failed to set text from markup due to error parsing markup: %s", + error->message); + g_free (str_for_display); + g_free (str_for_accel); + g_error_free (error); + return; + } + + g_free (str_for_display); + g_free (str_for_accel); if (text) gtk_label_set_text_internal (label, text);