summaryrefslogtreecommitdiff
path: root/gtk/gtkentry.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2016-01-27 02:07:35 +0100
committerBenjamin Otte <otte@redhat.com>2016-01-27 02:11:06 +0100
commita222aa66d5b7811798c3a98b0b0694de6fe4ec49 (patch)
tree6bd0ecf09b946ec2ff5c2bdfcbdced55478ce39a /gtk/gtkentry.c
parent84b788c4a5180978d5b87c976c1ef20d3dfffa64 (diff)
downloadgtk+-a222aa66d5b7811798c3a98b0b0694de6fe4ec49.tar.gz
entry: Compute selection range correctly
gtk_editable_get_selection_bounds() returns UTF-8 character offsets, but gdk_pango_layout_get_clip_region() wants byte ranges, so convert from one to the other. With English, this is especially visible for passwords, which use ● as the invisible character. https://bugzilla.gnome.org/show_bug.cgi?id=761128
Diffstat (limited to 'gtk/gtkentry.c')
-rw-r--r--gtk/gtkentry.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 1d11bbec1d..2854d940bc 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -6373,11 +6373,14 @@ gtk_entry_draw_text (GtkEntry *entry,
if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start_pos, &end_pos))
{
+ const char *text = pango_layout_get_text (layout);
+ gint start_index = g_utf8_offset_to_pointer (text, start_pos) - text;
+ gint end_index = g_utf8_offset_to_pointer (text, end_pos) - text;
cairo_region_t *clip;
gint range[2];
- range[0] = MIN (start_pos, end_pos);
- range[1] = MAX (start_pos, end_pos);
+ range[0] = MIN (start_index, end_index);
+ range[1] = MAX (start_index, end_index);
gtk_style_context_save_to_node (context, priv->selection_node);