summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-03-02 20:58:15 -0500
committerMatthias Clasen <mclasen@redhat.com>2021-03-02 20:58:15 -0500
commit8d1ea2ae42ca22bf991a598c4ee975a051141938 (patch)
tree27f7ab7da9a32898760d19b1a5c716e4a2201393
parent565c111c430410e0858b577fc97721659c407d0d (diff)
downloadpango-8d1ea2ae42ca22bf991a598c4ee975a051141938.tar.gz
markup: Fix two bugs
The docs state that all chars marked with the accel marker get an underline. But we were only underlining the first in each text chunk. Second, if an underline appears at the end of a text chunk, or at the end of the text, we would just eat it, which is unexpected.
-rw-r--r--pango/pango-markup.c50
1 files changed, 20 insertions, 30 deletions
diff --git a/pango/pango-markup.c b/pango/pango-markup.c
index b74c1ad4..d0b47016 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -677,8 +677,21 @@ text_handler (GMarkupParseContext *context G_GNUC_UNUSED,
/* The underline should go underneath the char
* we're setting as the next range_start
*/
- uline_index = md->index;
- uline_len = g_utf8_next_char (p) - p;
+ if (md->attr_list != NULL)
+ {
+ /* Add the underline indicating the accelerator */
+ PangoAttribute *attr;
+
+ attr = pango_attr_underline_new (PANGO_UNDERLINE_LOW);
+
+ uline_index = md->index;
+ uline_len = g_utf8_next_char (p) - p;
+
+ attr->start_index = uline_index;
+ attr->end_index = uline_index + uline_len;
+
+ pango_attr_list_change (md->attr_list, attr);
+ }
/* set next range_start to include this char */
range_start = p;
@@ -693,35 +706,12 @@ text_handler (GMarkupParseContext *context G_GNUC_UNUSED,
}
p = g_utf8_next_char (p);
- }
-
- if (range_end)
- {
- g_string_append_len (md->text,
- range_start,
- range_end - range_start);
- md->index += range_end - range_start;
- }
- else
- {
- g_string_append_len (md->text,
- range_start,
- end - range_start);
- md->index += end - range_start;
- }
-
- if (md->attr_list != NULL && uline_index >= 0)
- {
- /* Add the underline indicating the accelerator */
- PangoAttribute *attr;
-
- attr = pango_attr_underline_new (PANGO_UNDERLINE_LOW);
-
- attr->start_index = uline_index;
- attr->end_index = uline_index + uline_len;
+ }
- pango_attr_list_change (md->attr_list, attr);
- }
+ g_string_append_len (md->text,
+ range_start,
+ end - range_start);
+ md->index += end - range_start;
}
}